PHP code example of decorate / searchable

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

    

decorate / searchable example snippets


[  
    'name' => '>=',  
    'name2' => ['>='],  
    'name3' => ['name' => '='],  
    'name4' => 'like:name',  
    'name5' => 'like_forward:name',  
    'name6' => 'like_backward:name',  
    'name7' => function(Builder $q, $value) {  
        $q->whereNotNull($value);  
    },  
    'name8' => ['name' => function(Builder $q, $value) {  
        $q->where('id', $value);  
    }],  
    'title' => 'like:detail.title',  
    'title2' => ['detail.title' => '='],  
    'title3' => ['detail.title' => function(Builder $q, $value) {  
        $q->where('age', '>=', $value);  
    }],  
    'title4' => 'like:detail.',  
    'startDate' => 'between:begin_time',  
    'endDate' => 'between_end:begin_time',
    'level' => 'in:level_id',
    'level2' => 'in:detail.level_id'  
];

class User extends Model {
  use Searchable;
  
  public function getSearches(){
    return [
      'name' => 'like',
      'detail_name' => 'like:detail.name' 
    ];
  }
}

class UsersController extends Controller {
  
  public function index(Request $request) {
    return User::search($request);
  }
  
}

protected function injectSearch(Builder $builder, Request $request){
  $builder->where('id', '=', $request->query('id'));
}