PHP code example of camilo-manrique / laravel-filter

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

    

camilo-manrique / laravel-filter example snippets



'providers' => [
    CamiloManrique\LaravelFilter\FilterServiceProvider::class
]


User::filter($request)

User::filterandGet($request)

$user = User::find(1)
$user->posts()->filterAndGet($request);

Route::get('/users', function(){
    return User::filterAndGet(request());
});

public function index(Request $request){
    return User::filterAndGet($request);
}

Route::get('/users', function(){
    return UserResource::collection(User::filterAndGet(request()));
});

    namespace App\Http\Controllers;
    
    use App\Users;
    
    class UsersController extends Controller
    {
        public function filter(Request $request)
        {
            return User::filterAndGet($request);
        }
    }

    http://www.example.com/users?country=Germany

    http://www.example.com/users?country=Germany&gender=Male

    $filters = ["country" => "Germany", "gender" => "Male"]
    User::filterAndGet($filters);

    http://www.example.com/users?country=Germany&age%2Fend=30

    $filters = ["country" => "Germany", "age/end" => 30]
    User::filterAndGet($filters);

    $filters = ["country" => "Germany", "relationships" => "posts,comments"]
    User::filterAndGet($filters);

    $filters = ["account_info@name" => "John"]
    User::filterAndGet($filters);

    $filters = ["user_id" => 1, sum" => "votes"]
    User::filterAndGet($filters);

    $user = User::find(1)
    $filters = ["sum" => "votes"]
    $user->posts()->filterAndGet($filters);

php artisan vendor:publish