Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arvinlp/laravel-search-filter
Laravel Search Filter
https://github.com/arvinlp/laravel-search-filter
filter laravel laravel-filters laravel-search laravel6 php searching web
Last synced: 6 days ago
JSON representation
Laravel Search Filter
- Host: GitHub
- URL: https://github.com/arvinlp/laravel-search-filter
- Owner: arvinlp
- License: gpl-3.0
- Created: 2020-02-05T11:54:28.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-17T07:48:25.000Z (about 4 years ago)
- Last Synced: 2024-10-12T11:04:55.571Z (about 1 month ago)
- Topics: filter, laravel, laravel-filters, laravel-search, laravel6, php, searching, web
- Language: PHP
- Homepage: https://arvinlp.github.io/laravel-search-filter/
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# laravel-search-filter
Laravel Search Filter page on GitHub
How Use ?
in your controller instead of use routine method like :
$flight = App\Flight::pageination();
//Or
$flight = App\Flight::with('captain')->pageination();
//Or
$flight = App\Flight::where('active', 1)->pageination();
//Or
$flight = App\Flight::with('captain')->where('active', 1)->all();
//Or
$flight = App\Flight::with('captain')->where('active', 1)->get();
//Or
$flight = App\Flight::with('captain')->where('active', 1)->pageination();
With this class you can parsing get url and using one line code for fetching data with Eloquent and filtered data.
$flight = App\SearchFilter::apply( $request, new Flight, 'all', 'captain' );Function Arguments
SearchFilter::apply( Request, Model, Query Type, Relationships )
Request(Required) :
Illuminate\Http\Request $request;
Any request laravel can supported like Get, Post, Put, etc.
But for using search and filters using Get method !
Model(Required) :
Illuminate\Database\Eloquent\Model;
model should be extened of Eloquent Model. and just passing to function not more!
Query Type :
is String method or can be NULL.
- all : Get All Data
- get : Get Data
- pageination : Get Data With Pageination
When Query Type is Null or not selected by Default is 'pageination'.
Relationships :
When you need use Eloquent Relation in your query can send by this arg.
this arg like Main scopeWith can parsing array.
$relation = 'role';
//or
$relation = ['role','access'];
Add New Custom Filter
in directory "Filters" you can add new filter class.new filter class should be implements Filter and use Eloquent Builder for using functions related.
also if you need filter like father_name in your new filter class name is FatherName, under line removed and first character is upper.for example :
namespace App\SearchFilters\Filters;
use Illuminate\Database\Eloquent\Builder;
class NewFilter implements Filter{
/**
* Apply a given search value to the builder instance.
*
* @param Builder $builder
* @param mixed $value
* @return Builder $builder
*/
public static function apply(Builder $builder, $value){
return $builder->where('new_filter', "LIKE", "%".$value."%" );
}
}
Add Custom Request by PHP And Passed to Class
For Pass Custom Request to Class, you can using merge function in Request Class.
and just pass array with merge function to request :)
$request->merge([
"order_by" => "name",
"order" => "desc"
]);
Thank you
Arvin Loripour