created color search function
This commit is contained in:
@@ -24,6 +24,8 @@ class Color extends Component
|
||||
|
||||
public $createModal = false;
|
||||
|
||||
public $search ='';
|
||||
|
||||
public function create() {
|
||||
@Auth::check();
|
||||
|
||||
@@ -52,7 +54,7 @@ class Color extends Component
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.filament.color', [
|
||||
'colors' => ColorModel::paginate(10)
|
||||
'colors' => ColorModel::search('name', $this->search)->paginate(10)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -19,6 +20,10 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
// Search
|
||||
Builder::macro('search', function ($field, $string) {
|
||||
return $string ? $this->where($field, 'like', '%' . $string . '%') : $this;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user