PHP code example of mohamedgaber-intake40 / filter-quent

1. Go to this page and download the library: Download mohamedgaber-intake40/filter-quent 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/ */

    

mohamedgaber-intake40 / filter-quent example snippets


 'providers' => [
    \Filter\Providers\FilterServiceProvider::class
];

  class User extends Authenticatable 
  {
        use HasFilter;
  }

protected function getFilterClassName()
{
    return App\Filters\MyUserFilter::class;
}

protected function filterName($name)
{
    $this->query->where('name','like',"%$name%");
}

  protected function filterPosts($posts)
  {
      $this->query->whereHas('posts',function($q) use ($posts){
        $q->whereIn('id',$posts);
      });
  }
  

 App\Models\User::filter([ 'name' => 'test' , 'posts' => [1,2,3] ])->get();

  class User extends Authenticatable 
  {
      use HasSortable;
  }

/**
* The attributes that can be sorted.
*
* @var array<string>
*/
protected $sortable = [
  'id',
  'name',
  'created_at',
  'updated_at'
];

 App\Models\User::sortable()->get();

  class User extends Authenticatable 
  {
      use HasSelectable;
  }

/**
* The attributes that can be sorted.
*
* @var array<string>
*/
protected $selectable = [
  'id',
  'name',
  'created_at',
  'updated_at'
];

 App\Models\User::selectable()->get();