PHP code example of zaruto / scramble-spatie-query-builder
1. Go to this page and download the library: Download zaruto/scramble-spatie-query-builder 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/ */
zaruto / scramble-spatie-query-builder example snippets
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\QueryBuilder;
class UserController extends Controller
{
public function index(): AnonymousResourceCollection
{
$users = QueryBuilder::for(User::query())
->allowedFields(['id', 'name', 'email'])
->allowedFilters([
'name',
AllowedFilter::exact('email'),
])
->allowedIncludes(['posts', 'roles'])
->allowedSorts(['name', 'created_at'])
->paginate();
return UserResource::collection($users);
}
}
public function boot(): void
{
// ...
AllowedIncludesExtension::hook(function(Operation $operation, Parameter $parameter) {
// Customize the example
$parameter->example(['repositories.issues', 'repositories']);
// Customize the description
$parameter->description('Allows you to
AppServiceProvider.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.