PHP code example of enimiste / laravel-eloquent-filters
1. Go to this page and download the library: Download enimiste/laravel-eloquent-filters 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/ */
enimiste / laravel-eloquent-filters example snippets
use Illuminate\Database\Eloquent\Builder;
class LessonQueryFilters extends QueryFilters
{
/**
* @param string $order
* @return Builder
*/
public function popular($order = 'desc'): Builder
{
return $this->builder()->orderBy('views', $order);
}
/**
* @param $level
* @return Builder
*/
public function difficulty($level): Builder
{
return $this->builder()->where('difficulty', $level);
}
/**
* @param string $order
* @return Builder
*/
public function length($order = 'asc'): Builder
{
return $this->builder()->orderBy('length', $order);
}
}
class LessonController extends Controller
{
/**
* @param Request $request
* @return mixed
*/
public function index(Request $request)
{
$bag = new HttpRequestFiltersBag($request);
//$bag = new ArrayFiltersBag(['popular' => 'asc', 'difficulty' => 'beginner']);
$filter = new LessonQueryFilters($bag);
return Lesson::filter($filter)->get();//you can send results to a blade view
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.