PHP code example of cuongnd88 / lara-query-kit

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

    

cuongnd88 / lara-query-kit example snippets


	composer 

	php artisan vendor:publish --provider="Cuongnd88\LaraQueryKit\LaraQueryKitServiceProvider"

. . . .
use App\Traits\QueryKit;

class User extends Authenticatable
{
    use Notifiable;
    use HasOtpAuth;
    use HasGuardian;
    use QueryKit;

. . . .
}

    public function upsert()
    {
        $data = [
            ['name' => "Dean Ngo", 'email' => '[email protected]', 'mobile' => '84905005533', 'password' => Hash::make('123456')],
            ['name' => "Robert Neil", 'email' => '[email protected]', 'mobile' => '84905001122', 'password' => Hash::make('123456')],
        ];
        User::insertDuplicate($data, ['name', 'email', 'mobile', 'password'], ['name', 'email', 'mobile']);
    }

    public function listTableColumns()
    {
        $columns = User::getTableColumns();
        dump($columns);
    }

. . . .
use App\Traits\QueryKit;

class User extends Authenticatable
{
    use Notifiable;
    use HasOtpAuth;
    use HasGuardian;
    use QueryKit;

    protected $excludable = ['deleted_at', 'created_at', 'updated_at'];

. . . .
}

    public function listUsers()
    {
        $data = User::exclude()->get()->toArray();
        dump($data);
    }

    public function listUsers()
    {
        $users = User::exclude(['deleted_at', 'created_at', 'updated_at'])
                        ->get()->toArray();
        dump($users);
    }

. . . .
use App\Traits\QueryKit;

class User extends Authenticatable
{
    use Notifiable;
    use HasOtpAuth;
    use HasGuardian;
    use QueryKit;

    protected $filterable = [
        'id' => ['whereBetween'],
        'email',
        'name' => ['orWhere', 'LIKE', '%{name}%'],
    ];

. . . .
}

    public function filter()
    {
        $where = [
            'id' => [1,5],
            'email' => '[email protected]',
            'name' => 'ngo',
        ];

        $data = User::->filter($where)->get()->toArray();
    }

    public function filter()
    {
        $filterable = [
            'email',
            'name' => ['orWhere', 'LIKE', '%{name}%'],
            'deleted_at' => ['whereNull'],
        ];

        $where = [
            'email' => '[email protected]',
            'name' => 'ngo',
            'deleted_at' => '',
        ];

        $data = User::filterableCondition($filterable)
                        ->filter($where)
                        ->get()
                        ->toArray();
    }

. . . .
use App\Traits\QueryKit;

class User extends Authenticatable
{
    use Notifiable;
    use HasOtpAuth;
    use HasGuardian;
    use QueryKit;


    protected $excludable = ['deleted_at', 'created_at', 'updated_at'];

    protected $searchable = [
        'name', 'address'
    ];

. . . .
}

    public function search()
    {
        $data = User::searchFulltext('ngo')->exclude()->get()->toArray();
        dump($data);
    }

    public function search()
    {
        $data = User::searchableCols(['name', 'address'])
                        ->searchFulltext('ngo')
                        ->exclude()
                        ->get()
                        ->toArray();
        dump($data);
    }

ALTER TABLE `users` ADD FULLTEXT(`name`, `address`);