PHP code example of nahidulhasan / eloquent-filter

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

    

nahidulhasan / eloquent-filter example snippets

 
  

namespace App\Models;

use Illuminate\Database\Eloquent\Model;  
use NahidulHasan\EloquentFilter\Filterable;  
  
class Article extends Model  
{  
	use Filterable; 
	 
	/*
	* The attributes that are mass assignable. 
	*  @var array 
	*/ 
	protected $fillable = ['title', 'body'];
}  
  
  


namespace App\Filters;  
  
use Illuminate\Database\Eloquent\Builder;  
use NahidulHasan\EloquentFilter\QueryFilters;  
  
class ArticleFilters extends QueryFilters  
{  
  	/*  
	* Filter by Title. 
	* @param $title 
	* @return Builder 
	* @internal param $name 
	* @internal param string $level 
	*/ 
	public function title($title) { 
		return $this->builder->where('title', 'like', '%' .$title.'%'); 
	}
}  
  


namespace App\Http\Controllers;  
  
use App\Filters\ArticleFilters;  
use App\Models\Article;  
use Illuminate\Http\Request;  
  
/**  
* Class ArticleController 
* @package App\Http\Controllers 
*/
class ArticleController extends Controller  
{  
	/* 
	* Display a listing of the resource. 
	*  @param ArticleFilters $filters 
	*  @return \Illuminate\Http\Response 
	*  @internal param Request $request 
	*/ 
	public function index(ArticleFilters $filters) 
	{  
		$articles = Article::filter($filters)->paginate(5);  
		
		return view('articles.index', compact('articles'))->with('i', (request()->input('page', 1) - 1) * 5); 
	}
}