All Projects → nahidulhasan → Eloquent Filter

nahidulhasan / Eloquent Filter

This simple package helps you filter Eloquent data using query filters.

Projects that are alternatives of or similar to Eloquent Filter

Searchable
Search/filter functionality for Laravel's Eloquent models
Stars: ✭ 113 (+370.83%)
Mutual labels:  eloquent, laravel, filter
Laravel Mongodb
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
Stars: ✭ 5,860 (+24316.67%)
Mutual labels:  orm, eloquent, laravel
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (+62.5%)
Mutual labels:  eloquent, laravel, filter
eloquent-mongodb-repository
Eloquent MongoDB Repository Implementation
Stars: ✭ 18 (-25%)
Mutual labels:  eloquent, orm, filter
Laravel Optimistic Locking
Adds optimistic locking feature to eloquent models.
Stars: ✭ 71 (+195.83%)
Mutual labels:  orm, eloquent, laravel
Sieve
A simple, clean and elegant way to filter Eloquent models.
Stars: ✭ 123 (+412.5%)
Mutual labels:  eloquent, laravel, filter
Eloquentfilter
An Eloquent Way To Filter Laravel Models And Their Relationships
Stars: ✭ 1,113 (+4537.5%)
Mutual labels:  eloquent, laravel, filter
Gorose
GoRose(go orm), a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developer and python or ruby developer. Currently provides six major database drivers: mysql,sqlite3,postgres,oracle,mssql, Clickhouse.
Stars: ✭ 947 (+3845.83%)
Mutual labels:  orm, eloquent, laravel
Sarala
Javascript library to communicate with RESTful API built following JSON API specification. inspired by Laravel’s Eloquent
Stars: ✭ 101 (+320.83%)
Mutual labels:  orm, eloquent, laravel
Elasticsearch
The missing elasticsearch ORM for Laravel, Lumen and Native php applications
Stars: ✭ 375 (+1462.5%)
Mutual labels:  orm, eloquent, laravel
Queryablelist
Python module to add support for ORM-style filtering to any list of items
Stars: ✭ 19 (-20.83%)
Mutual labels:  orm, filter
Eloquent Ldap
A Laravel 5.1 package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.
Stars: ✭ 19 (-20.83%)
Mutual labels:  eloquent, laravel
Analogue
Analogue ORM : Data Mapper ORM for Laravel/PHP
Stars: ✭ 618 (+2475%)
Mutual labels:  orm, laravel
Befriended
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Stars: ✭ 596 (+2383.33%)
Mutual labels:  eloquent, laravel
Simple Cache
An easy to use Caching trait for Laravel's Eloquent Models.
Stars: ✭ 19 (-20.83%)
Mutual labels:  eloquent, laravel
Laravel Translatable
A Laravel package for multilingual models
Stars: ✭ 624 (+2500%)
Mutual labels:  eloquent, laravel
Eloquent Sortable
Sortable behaviour for Eloquent models
Stars: ✭ 914 (+3708.33%)
Mutual labels:  eloquent, laravel
Laravel Schemaless Attributes
Add schemaless attributes to Eloquent models
Stars: ✭ 595 (+2379.17%)
Mutual labels:  eloquent, laravel
Laravel Imageup
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image
Stars: ✭ 646 (+2591.67%)
Mutual labels:  eloquent, laravel
Laravel Friendships
This package gives Eloquent models the ability to manage their friendships.
Stars: ✭ 651 (+2612.5%)
Mutual labels:  eloquent, laravel

Laravel Eloquent Filter

Latest Stable Version Total Downloads Latest Unstable Version License

This simple package helps you filter Eloquent data using query filters.

Installation

Run the following command:

$ composer require nahidulhasan/eloquent-filter  

Getting started

Use the trait NahidulHasan\EloquentFilter\Filterable in your eloquent model.

Create a new class by extending the class NahidulHasan\EloquentFilter\QueryFilters and define your custom filters as methods with one argument. Where function names are the filter argument name and the arguments are the value.

Let's assume you want to allow to filter articles data. Please see the following code.

<?php  

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'];
}  
  

Create ArticleFilter class extending QueryFilters.

<?php

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.'%'); 
	}
}  

With this class we can use the http query string : title=article_name or any combination of these filters. It is up to you to define if you will use AND wheres or OR.

Now in the controller you can apply these filters like as described in below :

<?php

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); 
	}
}    

If you go to this link you will get all code: https://github.com/nahidulhasan/laravel-eloquent-query-filtering

Thanks to :

https://github.com/laracasts/Dedicated-Query-String-Filtering

License

Eloquent-Filter for Laravel is open-sourced software licensed under the MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].