PHP code example of marksihor / laravel-query-filter
1. Go to this page and download the library: Download marksihor/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/ */
marksihor / laravel-query-filter example snippets
namespace App\Http\Controllers;
...
use LaravelQueryFilter\FiltersQueries;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, FiltersQueries;
}
namespace App\Http\Controllers;
...
class PostController extends Controller
{
public function index(Request $request): JsonResponse
{
$collection = $this->filter(Post::query())->paginate(20);
return response()->json([
'data' => $collection
]);
}
}
namespace App\Models;
...
class Post extends Model
{
public array $filterableColumns = ['id', 'name', 'created_at', 'etc...'];
}