Merge pull request #2241 from burakcakirel/make-search-and-filters-extendable
Allow to add Module's fields to the search and filter
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Abstracts;
|
||||
|
||||
use App\Events\Common\SearchStringApplied;
|
||||
use App\Events\Common\SearchStringApplying;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Owners;
|
||||
use App\Traits\Sources;
|
||||
@ -116,9 +118,7 @@ abstract class Model extends Eloquent implements Ownable
|
||||
{
|
||||
$request = request();
|
||||
|
||||
$search = $request->get('search');
|
||||
|
||||
$query->usingSearchString($search)->sortable($sort);
|
||||
$query->usingSearchString()->sortable($sort);
|
||||
|
||||
if ($request->expectsJson() && $request->isNotApi()) {
|
||||
return $query->get();
|
||||
@ -129,6 +129,15 @@ abstract class Model extends Eloquent implements Ownable
|
||||
return $query->paginate($limit);
|
||||
}
|
||||
|
||||
public function scopeUsingSearchString($query)
|
||||
{
|
||||
event(new SearchStringApplying($query));
|
||||
|
||||
$this->getSearchStringManager()->updateBuilder($query, request('search'));
|
||||
|
||||
event(new SearchStringApplied($query));
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to export the rows of the current page filtered and sorted.
|
||||
*
|
||||
|
Reference in New Issue
Block a user