PHP code example of coderscantina / laravel-filter
1. Go to this page and download the library: Download coderscantina/laravel-filter 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/ */
coderscantina / laravel-filter example snippets
namespace App;
use CodersCantina\Filter\ExtendedFilter;
class TestFilter extends ExtendedFilter
{
public function name($name)
{
return $this->builder->where('name', $name);
}
public function latest()
{
return $this->builder->latest();
}
}
namespace App;
use Illuminate\Database\Eloquent\Model;
use CodersCantina\Filter\Filterable;
class TestModel extends Model
{
use Filterable;
}
namespace App\Http\Controllers;
use App\TestModel;
use App\TestFilter;
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Collection;
class LessonsController extends Controller
{
/**
* Show all lessons.
*
* @param Request $request
* @return Collection
*/
public function index(Request $request)
{
$filter = new TestFilter($request->all());
return TestModel::filter($filter)->get();
}
}
['sort' => '+foo,-bar']; // -> order by foo asc, bar desc
['sort' => '+foo.bar']; // -> left join x on x.id = foo.id order by foo.bar asc