<?php
$filters = EloquentFilters::make([
new NameFilter($request->name)
]);
$products = Product::filter($filters)->get();
use PricecurrentLaravelEloquentFiltersAbstractEloquentFilter;
use IlluminateDatabaseEloquentBuilder;
class NameFilter extends AbstractEloquentFilter
{
protected $name;
public function __construct($name)
{
$this->name = $name;
}
public function apply(Builder $builder): Builder
{
return $query->where('name', 'like', "{$this->name}%");
}
}
$filters = EloquentFilters::make([
new NameFilter($request->user_name)
]);
$products = User::query()
->filter($filters)
->limit(10)
->latest()
->get();