Git Product home page Git Product logo

laravel-search-filter's Introduction

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.

  1. all : Get All Data
  2. get : Get Data
  3. 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

laravel-search-filter's People

Contributors

arvinlp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.