Estoy tratando de filtrar los resultados desde la consulta en Eloquent, pero me marca el error BadMethodCallException
. Según yo lo estoy haciendo todo bien.
Tengo el siguiente código:
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,
]);
}
Donde SearchRequest
es:
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 [
//
];
}
}
Donde ConfigurationFilter
es:
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');
}
}
Donde ModelFilter
es:
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);
}
}
Donde ModelFilter
es:
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);
}
¿Que me estará faltando?
Gracias de antemano
ConfigurationFilter
public function scopeFilter($query, QueryFilter $filters) { return $filters->apply($query); }