PHP code example of fbsouzas / flery-builder

1. Go to this page and download the library: Download fbsouzas/flery-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/ */

    

fbsouzas / flery-builder example snippets




use Fbsouzas\FleryBuilder\FleryBuilder;
use Illuminate\Http\Request;

return FleryBuilder::to(User::class)
    ->apply($request->all())
    ->get();

// or

return FleryBuilder::to(User::class)
    ->apply([
        'where' => [
            'name' => 'Joe Doe',
        ],
    ])
    ->get();



use Fbsouzas\FleryBuilder\FleryBuilder;
use Illuminate\Http\Request;

return FleryBuilder::to(User::class)
    ->apply($request->all())
    ->where(['name' => 'Joe Doe'])
    ->get();

// or

return FleryBuilder::to(User::class)
    ->apply($request->all())
    ->join('contacts', function ($join) {
        $join->on('users.id', '=', 'contacts.user_id')
                ->where('contacts.user_id', '>', 5);
    }))
    ->get();

// or

return FleryBuilder::to(User::class)
    ->apply($request->all())
    ->whereJsonContains('options->languages', ['en', 'br'])
    ->get();

// and etc.

// That will return only the user's first name.
GET /api/users?fields=first_name

// or

// That will return only the user's first name and last name.
GET /api/users?fields=first_name,last_name

// That will return the user and his contact information.
GET /api/users?with=contact

// or

// That will return the user and his contact information and posts.
GET /api/users?with=contact;posts

// or

// That will return the user and just his posts title.
GET /api/users?with=posts:id,title

// That will return all users that have joe in their first names.
GET /api/users?search[first_name]=joe

// That will return a user's list ascendant ordered by the first name.
GET /api/users?sort=first_name

// or

// That will return a user's list descendant ordered by the first name.
GET /api/users?sort=-first_name