1. Go to this page and download the library: Download sufian/laravel-query-filter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sufian / laravel-query-filter example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Sufian\QueryFilter\Filterable;
class User extends Model
{
use Filterable;
}
namespace App\Filters;
use Sufian\QueryFilter\BaseFilter;
use Illuminate\Database\Eloquent\Builder;
class UserFilter extends BaseFilter
{
protected $filters = ['name', 'email'];
public function name(Builder $query, $value)
{
$query->where('name', 'like', '%' . $value . '%');
}
public function email(Builder $query, $value)
{
$query->where('email', 'like', '%' . $value . '%');
}
}
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index(Request $request)
{
$users = User::filter()->get();
return response()->json($users);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.