J'essaie de filtrer les résultats à partir de la requête eloquent, mais j'obtiens l'erreur suivante BadMethodCallException
. Selon moi, je fais tout ce qu'il faut.
J'utilise Laravel 5.4
Les détails de l'erreur :
BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::filter()
in Builder.php line 2445
at Builder->__call('filter', array(null))
in Builder.php line 1254
at Builder->__call('filter', array(null))
in web.php line 459
at Router->{closure}()
in Route.php line 189
at Route->runCallable()
in Route.php line 163
at Route->run()
in Router.php line 572
J'ai le code suivant :
public function index(SearchRequest $searchRequest, ConfigurationFilter $filters)
{
$filtered_configurations = Configuration::whereTrash(false)->with(['customs.properties', 'properties'])->filter($filters);
$types = $this->getConfigurationTypes();
$authors = $this->getAuthors();
return view('configuration.assistant.index', [
'configurations' => $filtered_configurations->paginate(10),
'authors' => $authors,
'types' => $types,
]);
}
Dónde SearchRequest
est :
class SearchRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return Auth::user()->author != null;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}
Dónde ConfigurationFilter
est :
class ConfigurationFilter extends ModelFilter
{
public function name($value)
{
return $this->builder->where('name', 'like', "%{$value}%");
}
public function author($id)
{
return $this->builder->whereIn('user_id', explode(',', $id));
}
public function type($type)
{
return $this->builder->whereIn('category_id', explode(',', $type));
}
public function status($status)
{
return $this->builder->whereEnabled($status == 'enabled');
}
}
Dónde ModelFilter
est :
class ModelFilter extends QueryFilter implements Filter
{
public function id($id)
{
return $this->builder->whereIn('id', explode(',', $id));
}
public function from($date)
{
return $this->builder->where('created_at', '>=', $date);
}
public function to($date)
{
return $this->builder->where('created_at', '<=', $date);
}
public function enabled($status)
{
return $this->builder->whereEnabled($status === 'true');
}
public function trash($status)
{
return $this->builder->whereTrash($status === 'true');
}
public function take($limit = 100)
{
return $this->builder->take($limit);
}
}
Dónde Filter
est :
interface Filter {
public function id($id);
public function from($date);
public function to($date);
public function enabled($status);
public function trash($status);
public function take($limit = 100);
}
Qu'est-ce qui va me manquer ?
Merci d'avance