PHP code example of xabou / query

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

    

xabou / query example snippets


public static function body()
{
    return User::select(['user.username', 'user.id', 'user.verified', 'popularity_user.score'])
                 ->join('popularity_user', 'users.id', '=', 'popularity_user.user_id')
                 ->where('user.verified', 1)
                 ->with('avatar')
                 ->orderBy('popularity_user.score', 'DESC')
                 ->orderBy('user.username', 'ASC');
}


// Dynamic static method calls
PopularUsersQuery::first()

// or
PopularUsersQuery::get()

// Dynamic method calls
(new PopularUsersQuery())->get()


public static function body()
{
    return User::select(['user.username', 'user.id', 'user.verified', 'popularity_user.score'])
                 ->join('popularity_user', 'users.id', '=', 'popularity_user.user_id')
                 ->where('user.verified', 1)
                 ->with('avatar')
                 ->orderBy('popularity_user.score', 'DESC')
                 ->paginate();
}


PopularUsersQuery::body()

//or

PopularUsersQuery::get()


PopularUsersQuery::body()->where('age', '>', 25)->get();


$age = 25;
$verified = 1 
PopularUsersQuery::get($age, $verified);

public static function body($age, $verified)
{
    return User::where('age', '>', $age)
                 ->where('verified', $verified);
}


php artisan make:query PopularUsersQuery