PHP code example of masoudi / laravel-sieve

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

    

masoudi / laravel-sieve example snippets


use Masoudi\Sieve\Filter;

class IndexPostsFilter extends Filter
{
    /**
     * Apply conditions on model
     * 
     * @param \Illuminate\Http\Request $request
     * @param \Illuminate\Database\Query\Builder $builder
     * 
     * @return \Illuminate\Database\Query\Builder
     */
    function filter(Request $request, Builder $builder)
    {
       $builder = $builder->where("is_active", true)
            ->where('published', true)
            ->whereHas('comments', function($query){
                $query->where('slug', '=', $request->slug);
            });
            
        return $builder;
    }
}

use Masoudi\Sieve\Filterable;

class Post extends Model { 
    
    use Filterable;
 }

Post::filter(new IndexPostsFilter)->get();