File: /home/armgroup/libs/app/Http/Livewire/Frontend/Header/MobileSearch.php
<?php
namespace App\Http\Livewire\Frontend\Header;
use App\Models\Product;
use Livewire\Component;
class MobileSearch extends Component
{
protected $queryString = ['q'];
public $q;
public $products = [];
public function updatedQ()
{
$this->products = [];
if (strlen(trim($this->q)) > 2) {
$this->products = Product::query()
->where('status', true)
->when($this->q, function ($query) {
foreach (explode(' ', $this->q) as $ph) {
$query = $query->where('name', 'LIKE', '%'.$ph.'%');
}
return $query;
})
->latest()
->select('id', 'name', 'slug', 'image')
->take(10)
->get();
}
}
public function render()
{
return view('livewire.frontend.header.mobile-search');
}
}