An Eloquent Way To Filter Laravel Models And Their Relationships

Overview

Eloquent Filter

Latest Stable Version Total Downloads Daily Downloads License StyleCI Build Status PHPUnit Status

An Eloquent way to filter Eloquent Models and their relationships

Introduction

Lets say we want to return a list of users filtered by multiple parameters. When we navigate to:

/users?name=er&last_name=&company_id=2&roles[]=1&roles[]=4&roles[]=7&industry=5

$request->all() will return:

[
    'name'       => 'er',
    'last_name'  => '',
    'company_id' => '2',
    'roles'      => ['1','4','7'],
    'industry'   => '5'
]

To filter by all those parameters we would need to do something like:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;

class UserController extends Controller
{

    public function index(Request $request)
    {
        $query = User::where('company_id', $request->input('company_id'));

        if ($request->has('last_name'))
        {
            $query->where('last_name', 'LIKE', '%' . $request->input('last_name') . '%');
        }

        if ($request->has('name'))
        {
            $query->where(function ($q) use ($request)
            {
                return $q->where('first_name', 'LIKE', $request->input('name') . '%')
                    ->orWhere('last_name', 'LIKE', '%' . $request->input('name') . '%');
            });
        }

        $query->whereHas('roles', function ($q) use ($request)
        {
            return $q->whereIn('id', $request->input('roles'));
        })
            ->whereHas('clients', function ($q) use ($request)
            {
                return $q->whereHas('industry_id', $request->input('industry'));
            });

        return $query->get();
    }

}

To filter that same input With Eloquent Filters:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;

class UserController extends Controller
{

    public function index(Request $request)
    {
        return User::filter($request->all())->get();
    }

}

Configuration

Install Through Composer

composer require tucker-eric/eloquentfilter

There are a few ways to define the filter a model will use:

Default Settings

The default namespace for all filters is App\ModelFilters\ and each Model expects the filter classname to follow the {$ModelName}Filter naming convention regardless of the namespace the model is in. Here is an example of Models and their respective filters based on the default naming convention.

Model ModelFilter
App\User App\ModelFilters\UserFilter
App\FrontEnd\PrivatePost App\ModelFilters\PrivatePostFilter
App\FrontEnd\Public\GuestPost App\ModelFilters\GuestPostFilter

Laravel

With Configuration File (Optional)

Registering the service provider will give you access to the php artisan model:filter {model} command as well as allow you to publish the configuration file. Registering the service provider is not required and only needed if you want to change the default namespace or use the artisan command

After installing the Eloquent Filter library, register the EloquentFilter\ServiceProvider::class in your config/app.php configuration file:

'providers' => [
    // Other service providers...

    EloquentFilter\ServiceProvider::class,
],

Copy the package config to your local config with the publish command:

php artisan vendor:publish --provider="EloquentFilter\ServiceProvider"

In the config/eloquentfilter.php config file. Set the namespace your model filters will reside in:

'namespace' => "App\\ModelFilters\\",

Lumen

Register The Service Provider (Optional)

This is only required if you want to use the php artisan model:filter command.

In bootstrap/app.php:

$app->register(EloquentFilter\LumenServiceProvider::class);
Change The Default Namespace

In bootstrap/app.php:

config(['eloquentfilter.namespace' => "App\\Models\\ModelFilters\\"]);

Define The Default Model Filter (optional)

The following is optional. If no modelFilter method is found on the model the model's filter class will be resolved by the default naming conventions

Create a public method modelFilter() that returns $this->provideFilter(Your\Model\Filter::class); in your model.

<?php

namespace App;

use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Filterable;

    public function modelFilter()
    {
        return $this->provideFilter(\App\ModelFilters\CustomFilters\CustomUserFilter::class);
    }

    //User Class
}

Dynamic Filters

You can define the filter dynamically by passing the filter to use as the second parameter of the filter() method. Defining a filter dynamically will take precedent over any other filters defined for the model.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use App\ModelFilters\Admin\UserFilter as AdminFilter;
use App\ModelFilters\User\UserFilter as BasicUserFilter;
use Auth;

class UserController extends Controller
{
    public function index(Request $request)
    {
        $userFilter = Auth::user()->isAdmin() ? AdminFilter::class : BasicUserFilter::class;

        return User::filter($request->all(), $userFilter)->get();
    }
}

Generating The Filter

Only available if you have registered EloquentFilter\ServiceProvider::class in the providers array in your `config/app.php'

You can create a model filter with the following artisan command:

php artisan model:filter User

Where User is the Eloquent Model you are creating the filter for. This will create app/ModelFilters/UserFilter.php

The command also supports psr-4 namespacing for creating filters. You just need to make sure you escape the backslashes in the class name. For example:

php artisan model:filter AdminFilters\\User

This would create app/ModelFilters/AdminFilters/UserFilter.php

Usage

Defining The Filter Logic

Define the filter logic based on the camel cased input key passed to the filter() method.

  • Empty strings and null values are ignored
  • If a setup() method is defined it will be called once before any filter methods regardless of input
  • _id is dropped from the end of the input key to define the method so filtering user_id would use the user() method
    • (can be changed with by definining protected $drop_id = false; on a filter)
  • Input without a corresponding filter method are ignored
  • The value of the key is injected into the method
  • All values are accessible through the $this->input() method or a single value by key $this->input($key)
  • All Eloquent Builder methods are accessible in $this context in the model filter class.

To define methods for the following input:

[
    'company_id'   => 5,
    'name'         => 'Tuck',
    'mobile_phone' => '888555'
]

You would use the following methods:

use EloquentFilter\ModelFilter;

class UserFilter extends ModelFilter
{
    protected $blacklist = ['secretMethod'];
    
    // This will filter 'company_id' OR 'company'
    public function company($id)
    {
        return $this->where('company_id', $id);
    }

    public function name($name)
    {
        return $this->where(function($q) use ($name)
        {
            return $q->where('first_name', 'LIKE', "%$name%")
                ->orWhere('last_name', 'LIKE', "%$name%");
        });
    }

    public function mobilePhone($phone)
    {
        return $this->where('mobile_phone', 'LIKE', "$phone%");
    }

    public function setup()
    {
        $this->onlyShowDeletedForAdmins();
    }

    public function onlyShowDeletedForAdmins()
    {
        if(Auth::user()->isAdmin())
        {
            $this->withTrashed();
        }
    }
    
    public function secretMethod($secretParameter)
    {
        return $this->where('some_column', true);
    }
}

Note: In the above example if you do not want _id dropped from the end of the input you can set protected $drop_id = false on your filter class. Doing this would allow you to have a company() filter method as well as a companyId() filter method.

Note: In the above example if you do not want mobile_phone to be mapped to mobilePhone() you can set protected $camel_cased_methods = false on your filter class. Doing this would allow you to have a mobile_phone() filter method instead of mobilePhone(). By default, mobilePhone() filter method can be called thanks to one of the following input key: mobile_phone, mobilePhone, mobile_phone_id

Note: In the example above all methods inside setup() will be called every time filter() is called on the model

Blacklist

Any methods defined in the blackist array will not be called by the filter. Those methods are normally used for internal filter logic.

The blacklistMethod() and whitelistMethod() methods can be used to dynamically blacklist and whitelist methods.

In the example above secretMethod() will not be called, even if there is a secret_method key in the input array. In order to call this method it would need to be whitelisted dynamically:

Example:

public function setup()
{
    if(Auth::user()->isAdmin()) {
        $this->whitelistMethod('secretMethod');
    }
}

Additional Filter Methods

The Filterable trait also comes with the below query builder helper methods:

EloquentFilter Method QueryBuilder Equivalent
$this->whereLike($column, $string) $query->where($column, 'LIKE', '%'.$string.'%')
$this->whereBeginsWith($column, $string) $query->where($column, 'LIKE', $string.'%')
$this->whereEndsWith($column, $string) $query->where($column, 'LIKE', '%'.$string)

Since these methods are part of the Filterable trait they are accessible from any model that implements the trait without the need to call in the Model's EloquentFilter.

Applying The Filter To A Model

Implement the EloquentFilter\Filterable trait on any Eloquent model:

<?php

namespace App;

use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Filterable;

    //User Class
}

This gives you access to the filter() method that accepts an array of input:

class UserController extends Controller
{
    public function index(Request $request)
    {
        return User::filter($request->all())->get();
    }
}

Filtering By Relationships

There are two ways to filter by related models. Using the $relations array to define the input to be injected into the related Model's filter. If the related model doesn't have a model filter of it's own or you just want to define how to filter that relationship locally instead of adding the logic to that Model's filter then use the related() method to filter by a related model that doesn't have a ModelFilter. You can even combine the 2 and define which input fields in the $relations array you want to use that Model's filter for as well as use the related() method to define local methods on that same relation. Both methods nest the filter constraints into the same whereHas() query on that relation.

For both examples we will use the following models:

A App\User that hasMany App\Client::class:

class User extends Model
{
    use Filterable;

    public function clients()
    {
        return $this->hasMany(Client::class);
    }
}

And each App\Client belongs to App\Industry::class:

class Client extends Model
{
    use Filterable;

    public function industry()
    {
        return $this->belongsTo(Industry::class);
    }
    
    public function scopeHasRevenue($query)
    {
        return $query->where('total_revenue', '>', 0);
    }
}

We want to query our users and filter them by the industry and volume potential of their clients that have done revenue in the past.

Input used to filter:

$input = [
    'industry'         => '5',
    'potential_volume' => '10000'
];

Setup

Both methods will invoke a setup query on the relationship that will be called EVERY time this relationship is queried. The setup methods signature is {$related}Setup() and is injected with an instance of that relations query builder. For this example let's say when querying users by their clients I only ever want to show agents that have clients with revenue. Without choosing wich method to put it in (because sometimes we may not have all the input and miss the scope all together if we choose the wrong one) and to avoid query duplication by placing that constraint on ALL methods for that relation we call the related setup method in the UserFilter like:

class UserFilter extends ModelFilter
{
    public function clientsSetup($query)
    {
        return $query->hasRevenue();
    }
}

This will prepend the query to the clients() relation with hasRevenue() whenever the UserFilter runs any constriants on the clients() relationship. If there are no queries to the clients() relationship then this method will not be invoked.

You can learn more about scopes here

Ways To Filter Related Models

Filter Related Models With The related() Method:

The related() method is a little easier to setup and is great if you aren't going to be using the related Model's filter to ever filter that Model explicitly. The related() method takes the same parameters as the Eloquent\Builder's where() method except for the first parameter being the relationship name.

Example:

UserFilter with an industry() method that uses the ModelFilter's related() method

class UserFilter extends ModelFilter
{
    public function industry($id)
    {
        return $this->related('clients', 'industry_id', '=', $id);
        
        // This would also be shorthand for the same query
        // return $this->related('clients', 'industry_id', $id);
    }
    
    public function potentialVolume($volume)
    {
        return $this->related('clients', 'potential_volume', '>=', $volume);
    }
}

Or you can even pass a closure as the second argument which will inject an instance of the related model's query builder like:

    $this->related('clients', function($query) use ($id) {
        return $query->where('industry_id', $id);
    });

Filter Related Models Using The $relations Array:

Add the relation in the $relations array with the name of the relation as referred to on the model as the key and an array of input keys that was passed to the filter() method.

The related model MUST have a ModelFilter associated with it. We instantiate the related model's filter and use the input values from the $relations array to call the associated methods.

This is helpful when querying multiple columns on a relation's table while avoiding multiple whereHas() calls for the same relationship. For a single column using a $this->whereHas() method in the model filter works just fine. In fact, under ther hood the model filter applies all constraints in the whereHas() method.

Example:

UserFilter with the relation defined so it's able to be queried.

class UserFilter extends ModelFilter
{
    public $relations = [
        'clients' => ['industry', 'potential_volume'],
    ];
}

ClientFilter with the industry method that's used to filter:

Note: The $relations array should identify the relation and the input key to filter by that relation. Just as the ModelFilter works, this will access the camelCased method on that relation's filter. If the above example was using the key industry_type for the input the relations array would be $relations = ['clients' => ['industry_type']] and the ClientFilter would have the method industryType().

class ClientFilter extends ModelFilter
{
    public $relations = [];

    public function industry($id)
    {
        return $this->where('industry_id', $id);
    }
    
    public function potentialVolume($volume)
    {
        return $this->where('potential_volume', '>=', $volume);
    }
}
$relations array alias support

The $relations array supports aliases. This is used when the input doesn't match the related model's filter method. This will transform the input keys being passed to the related model filter's input.

Example:
class UserFilter extends ModelFilter
{
    public $relations = [
        'clients' => [
            'client_industry'  => 'industry',
            'client_potential' => 'potential_volume'
        ]
    ];
}

The above will receive an array like:

[
    'client_industry'  => 1,
    'client_potential' => 100000
]

And the ClientFilter will receive it as:

[
    'industry'         => 1,
    'potential_volume' => 100000
]

Allowing for more descriptive input names without filters needing to match. Allowing for more reuse of the same filters.

Filter Related Models With Both Methods

You can even use both together and it will produce the same result and only query the related model once. An example would be:

If the following array is passed to the filter() method:

[
    'name'             => 'er',
    'last_name'        => ''
    'company_id'       => 2,
    'roles'            => [1,4,7],
    'industry'         => 5,
    'potential_volume' => '10000'
]

In app/ModelFilters/UserFilter.php:

<?php namespace App\ModelFilters;

use EloquentFilter\ModelFilter;

class UserFilter extends ModelFilter
{
    public $relations = [
        'clients' => ['industry'],
    ];
    
    public function clientsSetup($query)
    {
        return $query->hasRevenue();
    }

    public function name($name)
    {
        return $this->where(function($q)
        {
            return $q->where('first_name', 'LIKE', $name . '%')->orWhere('last_name', 'LIKE', '%' . $name.'%');
        });
    }
    
    public function potentialVolume($volume)
    {
        return $this->related('clients', 'potential_volume', '>=', $volume);
    }

    public function lastName($lastName)
    {
        return $this->where('last_name', 'LIKE', '%' . $lastName);
    }

    public function company($id)
    {
        return $this->where('company_id',$id);
    }

    public function roles($ids)
    {
        return $this->whereHas('roles', function($query) use ($ids)
        {
            return $query->whereIn('id', $ids);
        });
    }
}
Adding Relation Values To Filter

Sometimes, based on the value of a parameter you may need to push data to a relation filter. The push() method does just this. It accepts one argument as an array of key value pairs or to arguments as a key value pair push($key, $value). Related models are filtered AFTER all local values have been executed you can use this method in any filter method. This avoids having to query a related table more than once. For Example:

public $relations = [
    'clients' => ['industry', 'status'],
];

public function statusType($type)
{
    if($type === 'all') {
        $this->push('status', 'all');
    }
}

The above example will pass 'all' to the status() method on the clients relation of the model.

Calling the push() method in the setup() method will allow you to push values to the input for filter it's called on

Pagination

If you want to paginate your query and keep the url query string without having to use:

{!! $pages->appends(Input::except('page'))->render() !!}

The paginateFilter() and simplePaginateFilter() methods accept the same input as Laravel's paginator and returns the respective paginator.

class UserController extends Controller
{
    public function index(Request $request)
    {
        $users = User::filter($request->all())->paginateFilter();

        return view('users.index', compact('users'));
    }

OR:

    public function simpleIndex(Request $request)
    {
        $users = User::filter($request->all())->simplePaginateFilter();

        return view('users.index', compact('users'));
    }
}

In your view $users->render() will return pagination links as it normally would but with the original query string with empty input ignored.

Contributing

Any contributions welcome!

Comments
  • Does this work with Laravel 5.2 or is there a tag I can use that does?

    Does this work with Laravel 5.2 or is there a tag I can use that does?

    My app is Laravel 5.2 and so far all calls to Model::filter($request->input()) are returning all the models.

    Notice I have to use $request->input() as $request->all() does not work in Laravel 5.2.

    If there is a version of EloquentFilter that works with Laravel 5.2 please let me know or if it is known to require a higher version of Laravel.

    thanks.

    opened by serundeputy 45
  • Nested where not working

    Nested where not working

    This is my filter:

    public function search($search)
    	{
    		return $this->where(function($q) use ($search)
    		{
    			return $q->where('description', 'LIKE', "%$search%")
    			         ->orWhere('title', 'LIKE', "%$search%");
    		});
    	}
    

    But this is the query that's being run:

    select `listings`.*, (select count(*) from `media` where `listings`.`id` = `media`.`model_id` and `media`.`model_type` = 'App\Listing') as `media_count` from `listings` where (`description` LIKE 'App\Listing' or `title` LIKE '%a%') and `category_id` = '%a%' limit 2 offset 0
    

    For some reason, the first instance of $search is returning the classname of the model instead of the search term that's being passed through the query string. I'm unsure if I've just set this up incorrect or if it's a bug.

    opened by techdaddies-kevin 13
  • does not work with hybridrelations between mysql and mongodb relationships

    does not work with hybridrelations between mysql and mongodb relationships

    I know this is probably outside the scope of your project but I think it would be really cool if I could get it to work.

    I'm using https://github.com/jenssegers/laravel-mongodb which supports hybrid relations between mysql and mongodb models.

    I am able to do this no problem User::with('profile')->all();

    Where User is a mysql model and Profile is a mongodb model

    Furthermore your Filterable trait works out of the box on the mongodb model which is great and I am having a lot of enjoyment using it!

    so $users = User::filter($request->get()) and $profiles = Profile::filter($request->get()) both work great.

    But if I try to do $users = User::filter(['gender' => 'male'])->get(); then I get errors and the errors are basically showing that it is looking for the profile fields inside mysql instead of making those queries on the mongodb collection.

    I've set up my models properly

    My User model uses a UserFilter which has

        public function gender($value)
        {
            return $this->where('gender', $value);
        }
    

    And my ProfileFilter has

        public function gender($value)
        {
            return $this->where('gender', $value);
        }
    

    And I've confirmed that the gender function above DOES get called. But when it does I get this error

    SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'exists ? and `user_id` <> ? and `main_picture` is not null and `gender` = ?)' at line 1 (SQL: select * from `users` where exists (select `user_id` from `profile` where `user_id` exists 1 and `user_id` <> 201 and `main_picture` is not null and `gender` = male))
    

    Basically it's ignoring my HybridRelations setup and assuming that Profile is another mysql model.

    The fact that your EloquentFilter DOES work on my mongodb model when used without a relation tells me that this can probably be made to work without too much difficulty.

    Is there any chance you could add this functionality or put me in the right direction?

    I have a feeling part of the answer might lie in https://github.com/jenssegers/laravel-mongodb/blob/master/src/Jenssegers/Mongodb/Eloquent/HybridRelations.php

    Many thanks!

    opened by vesper8 11
  • small issue

    small issue

    Hello Thanks for this great package first, and secondly i have a small problem. the problem is i have a bulk of payments(table name = payment , fields: payment_date , payment_type : monthly, yearly ...) and as user can add one payment or more (payment 1, payment 2... +) it can be more than a payment. when i search with filter it getting the results but merging the payment 1 payment_date field with payment 2 payment_type field it like combining between 2 payments in the same time cause the payments belongs to a claim Note : a claim has many payment .

    opened by almokhtarbr 10
  • filter not work on scope query

    filter not work on scope query

    Hello, I have on query scope for enabled products which is:

        public function scopeEnabled($query)
        {
            return $query->where('enabled', true);
        }
    

    And I have scope by the name collect for search.

        public function scopeCollect($query, $sort = 'name')
        {
            $request = request();
            $input = $request->input();
            if(session('per-page')) {
                $limit = $request->get('limit', session('per-page'));
            } else {
                $limit = $request->get('limit', config('platform.per-page'));
            }
            return $query->filter($input)->sortable($sort)->paginate($limit);
        }
    

    When I use $products = Product::enabled()->collect(); it return only enabled products, collect function doesn't work.

    opened by aliqasemzadeh 9
  • How should you handle Laravel Scout integration?

    How should you handle Laravel Scout integration?

    I'm exploring the best way to integrate Laravel Scout using (custom) filters and it seems #37 ([https://github.com/Tucker-Eric/EloquentFilter/issues/37#issuecomment-321892146]) provides some information how one can integrate this nicely.

    However that ticket is created a few years ago and I don't know if things should be done differently nowadays.

    Could you please tell me if the same solution still is valid?

    Many thanks!

    opened by francoism90 8
  • Using OR relation

    Using OR relation

    I read the previous issues regarding using an OR relation - I've been able to make this work. The issue I've run into is applying the orWhere() only after the first filter. I'm including an attribute in the request to indicate whether or not the user would like all the filters to apply as OR or AND. However in order to make this work, the first filter needs to be a where() and the subsequent ones should use orWhere().

    opened by liran-co 8
  • BelongsToMany and paginateFilter() destroys pivot

    BelongsToMany and paginateFilter() destroys pivot

    When using the method paginateFilter() on a model with pivot table, this pivot table is not present inside the model. When changing back to paginate() the pivot model is back.

    companies - company_user - users

    In this case, if I would get all the users inside a company, and there would be any additional data inside the pivot table, it would be added inside the 'relations' object inside the model, but this is not present.

    opened by Cannonb4ll 7
  • Applying filter to a relationship collection

    Applying filter to a relationship collection

    Hi, I have User model which has relationship say books(), i want to do something like $user->books->filter($request->all()) so that user can only filter through his books.

    Any suggestion please.

    Thanks, Hussain

    opened by devchalkie 6
  • Arrays as multiple filters

    Arrays as multiple filters

    It seems that utilizing arrays does not account for the case that you may want to apply the same filter multiple times. Instead of calling the filter once with an array as the input, how can we achieve calling the filter multiple times with each input being one item in the array?

    opened by liran-co 6
  • No Method Name Validation or Whitelist

    No Method Name Validation or Whitelist

    At the moment, no validation or normalisation runs in the filterInput function. i.e. any key present in the input array will call a function with that name. This means any method can be called arbitrarily. For example, using the implementation as discussed in the readme, if one defines any (public or protected) function (e.g. superSecretMethod), then this could be called by visiting the appropriate endpoint with 'super_secret_method' as a query argument.

    This is unlikely to cause a major security issue, since no actions should really be defined within a Filter, and the output of the function is never returned to the user, however I don't think arbitrary method calls are a good idea.

    Some possible solutions:

    • create a whitelist of possible filters (i.e. require a parameter or function to be defined which specifies all the available filters)
    • come up with a common naming scheme for filters (e.g. get{FILTER_NAME}Filter, à la getFooAttribute)

    https://github.com/Tucker-Eric/EloquentFilter/blob/3a0ebf73cf436b18078d230406eb1c9b6e0ef496/src/ModelFilter.php#L185-L198

    opened by jpnut 6
  • $relations setting to create orWhereHas

    $relations setting to create orWhereHas

    I'm running into an issue where I would like to filter relations via an OR statement in staid of AND.

    e.g. I'm searching models on several columns by a search term. So many ModelFilters implement a query($term) method to search that model. Some models required deeper search through relations. We want to give the user as many results as possible for that search term. But the query has a whereHas instead of an orWhereHas so the result is restricted at the moment.

    A possible solution would be to manually write the orWhereHas in the top ModelFilter method, but this will end up into duplicate code since this method is also defined in the related ModelFilter.

    Would be awesome if this could be added!

    opened by lukevmk 3
  • Related filter does not accept zero or false value

    Related filter does not accept zero or false value

    If I try to execute related filter such as: relation_hasSomething=false or relation_hasSomething=0 related filter ignores these values, so I think that it's better to remove empty($value) condition in that line. I have overidden the method in my project and since that everything works fine https://github.com/Tucker-Eric/EloquentFilter/blob/5b55c3761e73d3842b8033bbccc6468c79d06184/src/ModelFilter.php#L653

    opened by b-aleksandrov 0
  • Postgresql support (case-insensitively)

    Postgresql support (case-insensitively)

    Hi,

    The following options are compatible with MySQL, but with Postgresql they do not work accordingly.

    $this->whereLike($column, $string) | $query->where($column, 'LIKE', '%'.$string.'%') -- | -- $this->whereBeginsWith($column, $string) | $query->where($column, 'LIKE', $string.'%') $this->whereEndsWith($column, $string) | $query->where($column, 'LIKE', '%'.$string)

    A simple change from "LIKE" to "ILIKE" (case-insensitively) would be necessary to make it work with Postgresql.

    However, it would have to be done "automatically" or pass as a parameter according to QueryBuilder Equivalent.

    In the "automatic" form, you can check the type of connection (DB_CONNECTION) that Laravel is using, as Laravel already has predefined connections, this test would give to check if the connection would be of the "mysql" or "pgsql" type and thus defining whether "LIKE" or "ILIKE" is used.

    opened by garbinmarcelo 2
Releases(3.1.0)
🕵️ Inspect Laravel Eloquent models to collect properties, relationships and more.

??️ Eloquent Inspector Inspect Laravel Eloquent models to collect properties, relationships and more. Install Via Composer composer require cerbero/el

Andrea Marco Sartori 111 Nov 4, 2022
The query filter bundle allows you to filter data from QueryBuilder and the Database.

The query filter bundle allows you to filter data from QueryBuilder and the Database. you can filter multiple columns at the same time and also you can filter relation fields with two-level deep and without any join in your query builder.

Bugloos 15 Dec 29, 2022
Laravel Eloquent BelongsToThrough relationships

Introduction This inverse version of HasManyThrough allows BelongsToThrough relationships with unlimited intermediate models. Supports Laravel 5.0+. I

Jonas Staudenmeir 804 Jan 3, 2023
This package gives Eloquent models the ability to manage their friendships.

Laravel 5 Friendships This package gives Eloquent models the ability to manage their friendships. You can easily design a Facebook like Friend System.

Alex Kyriakidis 690 Nov 27, 2022
Validate your input data in a simple way, an easy way and right way. no framework required. For simple or large. project.

wepesi_validation this module will help to do your own input validation from http request POST or GET. INTEGRATION The integration is the simple thing

Boss 4 Dec 17, 2022
Personal CRM. Remember everything about your friends, family and business relationships.

Personal Relationship Manager Monica is a great open source personal relationship management system. Introduction Purpose Features Who is it for? What

Monica 18.5k Jan 5, 2023
Laravel Ban simplify blocking and banning Eloquent models.

Laravel Ban Introduction Laravel Ban simplify management of Eloquent model's ban. Make any model bannable in a minutes! Use case is not limited to Use

cybercog 879 Dec 30, 2022
cybercog 996 Dec 28, 2022
Laravel Nova Ban simplify blocking and banning Eloquent models.

Laravel Nova Ban Introduction Behind the scenes cybercog/laravel-ban is used. Contents Installation Usage Prepare bannable model Prepare bannable mode

cybercog 39 Sep 29, 2022
Package with small support traits and classes for the Laravel Eloquent models

Contains a set of traits for the eloquent model. In future can contain more set of classes/traits for the eloquent database.

Martin Kluska 3 Feb 10, 2022
Use auto generated UUID slugs to identify and retrieve your Eloquent models.

Laravel Eloquent UUID slug Summary About Features Requirements Installation Examples Compatibility table Alternatives Tests About By default, when get

Khalyomede 25 Dec 14, 2022
Record created by, updated by and deleted by on Eloquent models automatically.

quarks/laravel-auditors Record created by, updated by and deleted by (if SoftDeletes added) on Eloquent models automatically. Installation composer re

Quarks 3 Jun 13, 2022
Observe (and react to) attribute changes made on Eloquent models.

Laravel Attribute Observer Requirements PHP: 7.4+ Laravel: 7+ Installation You can install the package via composer: composer require alexstewartja/la

Alex Stewart 55 Jan 4, 2023
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

Laravel Befriended Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked

Renoki Co. 720 Jan 3, 2023
Easy creation of slugs for your Eloquent models in Laravel

Eloquent-Sluggable Easy creation of slugs for your Eloquent models in Laravel. NOTE: These instructions are for the latest version of Laravel. If you

Colin Viebrock 3.6k Dec 30, 2022
Automatically validating Eloquent models for Laravel

Validating, a validation trait for Laravel Validating is a trait for Laravel Eloquent models which ensures that models meet their validation criteria

Dwight Watson 955 Dec 25, 2022
Tag support for Laravel Eloquent models - Taggable Trait

Laravel Taggable Trait This package is not meant to handle javascript or html in any way. This package handles database storage and read/writes only.

Rob 859 Dec 11, 2022
Preferences for Laravel Eloquent models

Preferences for Laravel Eloquent models Use this library to bind multiple key/value pair preferences to your application's Eloquent models. Preference

Kevin Laude 32 Oct 30, 2022
Laravel package to search through multiple Eloquent models.

Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.

Protone Media 845 Jan 1, 2023