PHP code example of hamba / queryget

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

    

hamba / queryget example snippets


class User extends Model{
    protected $fillable = [
        'username', 'email'
    ];

    public function roles()
    {
        return $this->belongsToMany(Role::class, 'role_users');
    }

    public $queryable = [
        'email' => 'string',//enable attribute email to be queried
        'name' => 'string:username',//enable attribute with alias
        'roles' => 'relation'//enable relation 'roles'
    ];
}

class Role extends Model
{
    protected $fillable = [
        'name', 'permissions',
    ];
    public $queryable = ['name', 'permissions'];
}

class UserController extends Controller
{
    public function index()
    {
        return qg(User::class)->apply()->get();
    }
}

Route::get('users', 'UserController@index');