<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mehdi Fathi</title>
    <description>The latest articles on DEV Community by Mehdi Fathi (@mehdifathi).</description>
    <link>https://dev.to/mehdifathi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F116625%2F4e3ee36b-7b3a-4183-ae45-d4c428bc68c9.jpeg</url>
      <title>DEV Community: Mehdi Fathi</title>
      <link>https://dev.to/mehdifathi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mehdifathi"/>
    <language>en</language>
    <item>
      <title>Simplify Eloquent Query Filtering in Laravel with Eloquent Filter</title>
      <dc:creator>Mehdi Fathi</dc:creator>
      <pubDate>Sun, 23 Mar 2025 07:14:19 +0000</pubDate>
      <link>https://dev.to/mehdifathi/simplify-eloquent-query-filtering-in-laravel-with-eloquent-filter-34c2</link>
      <guid>https://dev.to/mehdifathi/simplify-eloquent-query-filtering-in-laravel-with-eloquent-filter-34c2</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Filtering data in Laravel applications can become repetitive and messy, especially when dealing with complex queries. If you have ever done an advanced search page or reporting system, you know this fact managing this feature is difficult.&lt;/p&gt;

&lt;p&gt;Mention that Eloquent Filter is a package that simplifies this process by providing a clean and reusable way to filter Eloquent models.&lt;/p&gt;

&lt;p&gt;The link to the checkout is &lt;a href="https://github.com/mehdi-fathi/eloquent-filter" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt; Eloquent Filter repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Eloquent Filter?
&lt;/h2&gt;

&lt;p&gt;Explain what the package does: It allows you to filter Eloquent models based on query parameters. It helps keep your controllers clean by moving filtering logic into dedicated filter classes.&lt;/p&gt;

&lt;p&gt;It supports dynamic filtering, making it easy to add or modify filters without changing your codebase extensively.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight its key features:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Easy to install and configure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports complex filtering conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Works seamlessly with Laravel’s Eloquent ORM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supports query builder.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;

&lt;p&gt;Run the Composer command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composer require mehdi-fathi/eloquent-filter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2- Add &lt;code&gt;eloquentFilter\ServiceProvider::class&lt;/code&gt; to provider &lt;code&gt;app.php&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;   &lt;span class="s1"&gt;'providers'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
     &lt;span class="cm"&gt;/*
      * Package Service Providers...
      */&lt;/span&gt;
      &lt;span class="nc"&gt;eloquentFilter\ServiceProvider&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;
   &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the latest Laravel version add it to &lt;code&gt;providers.php&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nc"&gt;App\Providers\AppServiceProvider&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;eloquentFilter\ServiceProvider&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3- Add Facade &lt;code&gt;'EloquentFilter' =&amp;gt; eloquentFilter\Facade\EloquentFilter::class&lt;/code&gt; to aliases app.php&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'alias'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="cm"&gt;/*
   * Facade alias...
   */&lt;/span&gt;
    &lt;span class="s1"&gt;'EloquentFilter'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;eloquentFilter\Facade\EloquentFilter&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Basic Usage
&lt;/h1&gt;

&lt;p&gt;Add the &lt;code&gt;Filterable&lt;/code&gt; trait to your models and set fields in the whitelist array in which you will want to use of&lt;br&gt;
filter.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can override this method in your models as well.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;eloquentFilter\QueryFilter\ModelFilters\Filterable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Filterable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nv"&gt;$whiteListFilter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'username'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'created_at'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'updated_at'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;You can set &lt;code&gt;*&lt;/code&gt; char for that filter in all fields.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  A simple implementation with Eloquent Filter
&lt;/h3&gt;

&lt;p&gt;Eloquent Filter can help you to manage these features. Just you will set the query string to work with that.&lt;br&gt;
It would make your own query automatically and systematically while you can control them.&lt;/p&gt;

&lt;p&gt;Right after installing Eloquent Filter, the request URI would be like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?age_more_than[operator]=&amp;gt;&amp;amp;age[value]=35&amp;amp;gender=male&amp;amp;created_at[operator]==&amp;gt;&amp;amp;created_at[value]=25-09-2019
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;And in the Controller, You just need that one line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/**
 * Class UsersController.
 */&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Http\Controllers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UsersController&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Eloquent Filter is supporting query builder &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Usage is just extremely like model you need to use filter as a method. Obviously, there's no need for any change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt; &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'users'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conditions Guidance Table
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;To better understand this, I provided a table of all conditions and samples. It represents how eloquent filter
detect params and each param what query would make.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Condition Name&lt;/th&gt;
&lt;th&gt;Eloquent Method&lt;/th&gt;
&lt;th&gt;Param&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Eloquent&lt;/th&gt;
&lt;th&gt;DB&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;WhereCustomCondition&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Declared custom&lt;br&gt; method of Model&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SpecialCondition&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;f_params[limit]=10&lt;/td&gt;
&lt;td&gt;support f_params, e.g:&lt;br&gt; limit and order&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereBetweenCondition&lt;/td&gt;
&lt;td&gt;whereBetween&lt;/td&gt;
&lt;td&gt;created_at[start]=2016/05/01&lt;br&gt;&amp;amp;created_at[end]=2017/10/01&lt;/td&gt;
&lt;td&gt;whereBetween(&lt;br&gt;'created_at',&lt;br&gt; [{start},{end}])&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereByOptCondition&lt;/td&gt;
&lt;td&gt;where&lt;/td&gt;
&lt;td&gt;count_posts[operator]=&amp;gt;&amp;amp;&lt;br&gt;count_posts[value]=35&lt;/td&gt;
&lt;td&gt;where('count_posts',&lt;br&gt; "&amp;gt;", $value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereLikeCondition&lt;/td&gt;
&lt;td&gt;where&lt;/td&gt;
&lt;td&gt;first_name[like]=John&lt;/td&gt;
&lt;td&gt;where('first_name',&lt;br&gt; 'like', $value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereInCondition&lt;/td&gt;
&lt;td&gt;whereIn&lt;/td&gt;
&lt;td&gt;username[]=David&amp;amp;&lt;br&gt;username[]=John12&lt;/td&gt;
&lt;td&gt;whereIn('username', $value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereOrCondition&lt;/td&gt;
&lt;td&gt;orWhere&lt;/td&gt;
&lt;td&gt;username=Bill&amp;amp;&lt;br&gt;or[username]=James&lt;/td&gt;
&lt;td&gt;orWhere('username', $value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereHas&lt;/td&gt;
&lt;td&gt;WhereHas&lt;/td&gt;
&lt;td&gt;posts[title]=sport one&lt;/td&gt;
&lt;td&gt;whereHas('posts',&lt;br&gt;function ($q) &lt;br&gt;{$q-&amp;gt;where('title', $value)});&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereDoesntHaveCondition&lt;/td&gt;
&lt;td&gt;whereDoesntHave&lt;/td&gt;
&lt;td&gt;doesnt_have=category&lt;/td&gt;
&lt;td&gt;doesntHave($value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereDateCondition&lt;/td&gt;
&lt;td&gt;whereDate&lt;/td&gt;
&lt;td&gt;created_at=2024-09-01&lt;/td&gt;
&lt;td&gt;whereDate('created_at', $value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereYearCondition&lt;/td&gt;
&lt;td&gt;whereYear&lt;/td&gt;
&lt;td&gt;created_at[year]=2024&lt;/td&gt;
&lt;td&gt;whereYear('created_at', $value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereMonthCondition&lt;/td&gt;
&lt;td&gt;whereMonth&lt;/td&gt;
&lt;td&gt;created_at[month]=3&lt;/td&gt;
&lt;td&gt;whereMonth('created_at', $value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereDayCondition&lt;/td&gt;
&lt;td&gt;whereDay&lt;/td&gt;
&lt;td&gt;created_at[day]=15&lt;/td&gt;
&lt;td&gt;whereDay('created_at', $value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereNullCondition&lt;/td&gt;
&lt;td&gt;whereNull&lt;/td&gt;
&lt;td&gt;username[null]=true&lt;/td&gt;
&lt;td&gt;whereNull('username')&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereNotNullCondition&lt;/td&gt;
&lt;td&gt;whereNotNull&lt;/td&gt;
&lt;td&gt;username[not_null]=true&lt;/td&gt;
&lt;td&gt;whereNotNull('username')&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WhereCondition&lt;/td&gt;
&lt;td&gt;where&lt;/td&gt;
&lt;td&gt;username=Mehdi&lt;/td&gt;
&lt;td&gt;where('username', $value)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Simple Examples
&lt;/h3&gt;

&lt;p&gt;You just pass data form as query string. For example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Where&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?email=mehdifathi.developer@gmail.com

SELECT ... WHERE ... email = 'mehdifathi.developer@gmail.com'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?first_name=mehdi&amp;amp;last_name=fathi

SELECT ... WHERE ... first_name = 'mehdi' AND last_name = 'fathi'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If you send date format &lt;code&gt;Y-m-d&lt;/code&gt; we will work like &lt;code&gt;WhereDate()&lt;/code&gt; method Laravel.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?created_at=2024-09-01

SELECT ... WHERE ... strftime('%Y-%m-%d', "created_at") = cast(2024-09-01 as text)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Where In&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This example make method &lt;code&gt;whereIn&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?username[]=ali&amp;amp;username[]=ali22&amp;amp;family=ahmadi

SELECT ... WHERE ... username in ('ali','ali22') AND family = 'ahmadi'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;OrWhere&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This example make method &lt;code&gt;orWhere()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?name=mehdi&amp;amp;username=fathi&amp;amp;or[username]=ali

SELECT ... WHERE ... name = 'mehdi' AND username = 'fathi' or username = 'ali'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Where like&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are going to make a query by like conditions. You can do that by this example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?first_name[like]=%John%

SELECT ... WHERE ... first_name LIKE '%John%'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Where by operator&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can set any operator mysql in the queries string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?count_posts[operator]=&amp;gt;&amp;amp;count_posts[value]=35

SELECT ... WHERE ... count_posts &amp;gt; 35
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?username[operator]=!=&amp;amp;username[value]=ali

SELECT ... WHERE ... username != 'ali'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?count_posts[operator]=&amp;lt;&amp;amp;count_posts[value]=25

SELECT ... WHERE ... count_posts &amp;lt; 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Where the nested relations Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can set all nested relations in the query string just via the array of query string. Imagine, the user model has a&lt;br&gt;
relation with posts. And posts table has a relation with orders table.&lt;/p&gt;

&lt;p&gt;You can make query conditions by set &lt;code&gt;posts[count_post]&lt;/code&gt; and &lt;code&gt;posts[orders][name]&lt;/code&gt; in the query string.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Just be careful you must set &lt;code&gt;posts.count_post&lt;/code&gt; and &lt;code&gt;posts.orders.name&lt;/code&gt; in the User model.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;eloquentFilter\QueryFilter\ModelFilters\Filterable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Filterable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nv"&gt;$whiteListFilter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'username'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'posts.count_post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'posts.category'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'posts.orders.name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="cd"&gt;/**
     * @return \Illuminate\Database\Eloquent\Relations\belongsTo
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;belongsTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Models\Post'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?posts[count_post]=876&amp;amp;username=mehdi

select * from "users" where exists 
         (select * from "posts" where "posts"."user_id" = "users"."id" 
         and "posts"."count_post" = 876)
         and "username" = "mehdi"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;The above example is the same code that you used without the eloquent filter. Check it under code. It's not amazing?
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$builder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'posts'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$builder&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;whereHas&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'posts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$q&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$q&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'count_post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;876&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'username'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'mehdi'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;&lt;em&gt;Where array the nested relation Model&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can pass array to make whereIn condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?posts[category][]=php&amp;amp;posts[category][]=laravel&amp;amp;posts[category][]=jquery&amp;amp;username=mehdi

select * from "users" where exists 
         (select * from "posts" where 
         "posts"."category" in ('php','laravel','jquery') )
         and "username" = "mehdi"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Doesnthave Where (new feature)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/tags/list?doesnt_have=category

select * from "tags" where not exists (select * from "categories" where "tags"."foo_id" = "categories"."id")'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To fetching those data that doesn't have any relationship with the model as the same &lt;code&gt;Doesnthave&lt;/code&gt; method worked.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;strong&gt;&lt;em&gt;Special Params&lt;/em&gt;&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;You can set special params &lt;code&gt;limit&lt;/code&gt; and &lt;code&gt;orderBy&lt;/code&gt; in the query string to make a query by that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?f_params[limit]=1

SELECT ... WHERE ... order by `id` desc limit 1 offset 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?f_params[orderBy][field]=id&amp;amp;f_params[orderBy][type]=ASC

SELECT ... WHERE ... order by `id` asc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?f_params[orderBy][field]=id,count_posts&amp;amp;f_params[orderBy][type]=ASC

SELECT ... WHERE ...  order by `id` asc, `count_posts` asc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Where between&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are going to make a query based on date, You must fill keys, &lt;code&gt;start&lt;/code&gt;, and &lt;code&gt;end&lt;/code&gt; in the query string.&lt;br&gt;
Hence You can set it as a query string. These params are used for the filter by date.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?created_at[start]=2016/05/01&amp;amp;created_at[end]=2017/10/01

SELECT ... WHERE ... created_at BETWEEN '2016/05/01' AND '2017/10/01'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;strong&gt;&lt;em&gt;Advanced Where&lt;/em&gt;&lt;/strong&gt;*&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?count_posts[operator]=&amp;gt;&amp;amp;count_posts[value]=10&amp;amp;username[]=ali&amp;amp;username[]=mehdi&amp;amp;family=ahmadi&amp;amp;created_at[start]=2016/05/01&amp;amp;created_at[end]=2020/10/01
&amp;amp;f_params[orderBy][field]=id&amp;amp;f_params[orderBy][type]=ASC

select * from `users` where `count_posts` &amp;gt; 10 and `username` in ('ali', 'mehdi') and 
`family` = ahmadi and `created_at` between '2016/05/01' and '2020/10/01' order by 'id' asc limit 10 offset 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Therefore, fields of query string are same rows table database in &lt;code&gt;$whiteListFilter&lt;/code&gt; in your model or declare the method in your model as override method.&lt;br&gt;
The overridden method can be considered a custom query filter.&lt;/p&gt;

&lt;p&gt;For more information about the feature's Eloquent Filter, you'd better see the &lt;a href="https://github.com/mehdi-fathi/eloquent-filter" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt; Eloquent Filter repository.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>eloquent</category>
      <category>mysql</category>
      <category>php</category>
    </item>
    <item>
      <title>Reaching an improved realistic testing approach in the Laravel feature test</title>
      <dc:creator>Mehdi Fathi</dc:creator>
      <pubDate>Mon, 25 Mar 2024 12:05:50 +0000</pubDate>
      <link>https://dev.to/mehdifathi/reaching-an-improved-realistic-testing-approach-in-the-laravel-feature-test-4gi3</link>
      <guid>https://dev.to/mehdifathi/reaching-an-improved-realistic-testing-approach-in-the-laravel-feature-test-4gi3</guid>
      <description>&lt;p&gt;It's been some time since I felt a gap in integration testing applications like feature tests in Laravel. At first look, we think running a few isolated tastes without any effects of other actions would be reliable. Let's talk about the pros and cons. I'll bring a way to a real enterprise application that would be enhanced against incoming problems like a chess super grandmaster playing blindfold chess.&lt;/p&gt;




&lt;p&gt;Imagine you have a complicated enterprise application with hundreds of feature tests. You should provide a bunch of data with the factory to ensure the tests would be passed. &lt;strong&gt;However in reality this might not happen. I mean either the user's behavior or consequently users' data generated by themselves aren't like test processes completely&lt;/strong&gt;. Therefore users might encounter a few errors that those cases weren't thought of in advance.&lt;/p&gt;

&lt;p&gt;Additionally, you can't consider each of the scenarios in detail. You know an enterprise application would have dozens of conditions in every action.&lt;strong&gt;Whether we can make a specific test for every one of them?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;on the other hand, since some applications don't have feature tests from the beginning, Writing tests for current code is like reading the whole source code to ensure considering everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  1- Isolated tests are useful for running individually, not continuously
&lt;/h2&gt;

&lt;p&gt;Isolated tests would be a flaw in the case of complex applications. Because end users will send requests to a bunch of endpoints to make their data, they send a request to that endpoint to see their result. &lt;/p&gt;

&lt;p&gt;In other words, in production, other's actions would impact your method however you declare a way to pass your test in the feature test Laravel by mocking and factory data. It might lead to false confidence in the code.&lt;/p&gt;

&lt;p&gt;In this way, You want to make sure that the code works well without any effect of other methods while real application would impact other actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  2- Unable to consider all aspects and scenarios
&lt;/h2&gt;

&lt;p&gt;Considering all aspects and scenarios tests in advance or in coding time would be tough. The code might be updated every day then writing tests might be for each change might impossible. Meanwhile, the developer who adds a new change is the best person to refactor or implement the tests.&lt;/p&gt;

&lt;p&gt;So generally, other developers don't want to implement tests for other developers' code. Furthermore, how often should we mock other services such as sending emails, notifications, and SMS or third-party endpoints? These days our dependencies have been enhancing these types of services. Therefore mocking them can be deceptive sometimes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Sicilian Test Orchestra would be more realistic tests
&lt;/h2&gt;

&lt;p&gt;We shouldn't expect feature tests to test all aspects completely although feature tests are really useful However I want to introduce a new way to fill this gap I mentioned.&lt;/p&gt;

&lt;p&gt;I've been working on a new package that provides a testing process like the end users' behavior called &lt;strong&gt;Sicilian Test Orchestra&lt;/strong&gt;&lt;a href="https://github.com/mehdi-fathi/sicilian-test-orchestra"&gt;Github&lt;/a&gt;. It sends a bunch of different requests to every one of the methods continuously without any database truncating then shows in detail and saves all reports in the database.&lt;/p&gt;

&lt;p&gt;There's no need to code for every method. You just need to declare routes with its requests and we run randomized to detect what the application reacts. For example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
$ composer require mehdi-fathi/sicilian-test-orchestra

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'providers' =&amp;gt; [
  /*
   * Package Service Providers...
   */
   SicilianTestOrchestra\SicilianTestOrchestraServiceProvider::class
]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
namespace Tests\Feature;

// use Illuminate\Foundation\Testing\RefreshDatabase;
use SicilianTestOrchestra\RequestStrategyTestable;
use Tests\TestCase;

class ExampleTest extends TestCase
{

    use RequestStrategyTestable;

    protected array $testOrchestraRequests = [
      'user_login' =&amp;gt; ['auth'],  //auth,quest
      'shuffle_next' =&amp;gt; true,
      'next' =&amp;gt; [
          [
              'route' =&amp;gt; 'save',
              'method' =&amp;gt; 'post',
              'data' =&amp;gt; [
                  'body' =&amp;gt; ['string', 'min:1', 'max:4'],
              ],
              'call' =&amp;gt; 1,
              'call_shuffle' =&amp;gt; 5,
          ],
          [
              'route' =&amp;gt; 'update',
              'method' =&amp;gt; 'put',
              'data' =&amp;gt; [
                  'body' =&amp;gt; ['string', 'min:1', 'max:4'],
              ],
              'param' =&amp;gt; [
                  'id' =&amp;gt; ['numeric', 'min:1', 'max:1']
              ],
              'call' =&amp;gt; 1,
              'call_shuffle' =&amp;gt; 2,
          ],
          [
              'route' =&amp;gt; 'list',
              'method' =&amp;gt; 'get',
              'data' =&amp;gt; [],
              'call' =&amp;gt; 1,
              'call_shuffle' =&amp;gt; 2,
          ],
          [
              'route' =&amp;gt; 'show',
              'method' =&amp;gt; 'get',
              'data' =&amp;gt; [
                  'id' =&amp;gt; ['numeric', 'min:1', 'max:1']
              ],
              'call' =&amp;gt; 1,
              'call_shuffle' =&amp;gt; 2,
          ],
          [
              'route' =&amp;gt; 'destroy',
              'method' =&amp;gt; 'get',
              'data' =&amp;gt; [
                  'id' =&amp;gt; ['numeric', 'min:1', 'max:1']
              ],
              'call' =&amp;gt; 1,
              'call_shuffle' =&amp;gt; 2,
          ],
          [
              'route' =&amp;gt; 'show',
              'method' =&amp;gt; 'get',
              'data' =&amp;gt; [
                  'id' =&amp;gt; ['numeric', 'min:1', 'max:1']
              ],
              'call' =&amp;gt; 1,
              'call_shuffle' =&amp;gt; 2,

          ],
      ]
];

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this command to create migration for the report_tests table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan vendor:publish --tag=migrations

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You declare treat of your methods as above so run your tests :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the data key, we've taken advantage of Faker lib to generate data. call_shuffle is a key to number call randomly without any order.&lt;/p&gt;

&lt;p&gt;You'll see all the results of tests in detail. every time you run tests you can see some new response. In addition, We keep those on a table to check what happened in tests. It should be better to run many times in a task schedule.&lt;/p&gt;

&lt;h2&gt;
  
  
  About Sicilian Test Orchestra in detail
&lt;/h2&gt;

&lt;p&gt;Since this package is new, I want to foster that gradually. As I mentioned, this package would be used to test Laravel Applications, potentially. This project is released recently in the 1.0 version. What would encourage me to develop is to read your ideas and viewpoints. &lt;strong&gt;So Not only I would like to know your thoughts about that gap in the feature test But also your view about the Sicilian Test Orchestra would be helpful&lt;/strong&gt;. This package has a long way to go. I would like you to comment freely or make an issue in my GitHub.&lt;/p&gt;

&lt;p&gt;For more details check out &lt;a href="https://github.com/mehdi-fathi/sicilian-test-orchestra"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt; repository&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>tests</category>
      <category>software</category>
      <category>php</category>
    </item>
    <item>
      <title>Introduce Eloquent Filter 2 in Laravel</title>
      <dc:creator>Mehdi Fathi</dc:creator>
      <pubDate>Fri, 12 Jun 2020 17:38:29 +0000</pubDate>
      <link>https://dev.to/mehdifathi/introduce-eloquent-filter-2-in-laravel-12g5</link>
      <guid>https://dev.to/mehdifathi/introduce-eloquent-filter-2-in-laravel-12g5</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Have you ever experienced make an advanced search page in programming? if your answer is yes maybe you know this feature has many conditions to make a query database. Especially when you are using a relational DB as MySQL in your project at that time our task will be getting hard. I was searching for it. Eventually, I found a clean way to implement this feature in the Laravel project. I want to introduce the Eloquent Filter to implement this feature in the laravel.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the main problem?
&lt;/h2&gt;

&lt;p&gt;The main problem is that you will make many conditions for every situation. Writing a lot of terms will surely reduce the readability of your code and increase the possibility of making a mistake.&lt;br&gt;
Practical example:&lt;br&gt;
Suppose we want to get the list of the users with the requested parameters as follows in the laravel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:8000/users/search?age_more_than=25&amp;amp;gender=male&amp;amp;created_at=25-09-2019
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The Request parameter will be as follows:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 
  'age_more_than' =&amp;gt; '24',
  'gender' =&amp;gt; 'male',
  'created_at' =&amp;gt; '25-09-2019',
]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Implement this feature in &lt;code&gt;UsersController.php&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;We check out a condition for each request.&lt;/p&gt;

&lt;p&gt;In the future, if your project will need more filter requests at that time you should add many conditions to the above code. Imagine some of the queries may be advanced therefore your code to be like &lt;strong&gt;Monster&lt;/strong&gt;!&lt;/p&gt;

&lt;h1&gt;
  
  
  Discover away
&lt;/h1&gt;

&lt;p&gt;Everything began from just a tutorial video called &lt;code&gt;Eloquent Techniques&lt;/code&gt; in laracast. It was about a new way to make an advanced filter by use of the query string in the Laravel. It has to separate layer filters from controller and model. It made an Eloquent query by the use of a query string. Advanced Eloquent rescued the readability of your code by a filter class. It was very good but you had to make a method for every condition. It's boring for a creative developer. You don't have a dynamic query and you have to write many methods for per condition just in a separate layer.&lt;/p&gt;

&lt;h1&gt;
  
  
  Eloquent Filter is your solution
&lt;/h1&gt;

&lt;p&gt;Imagine you will install a package composer and make a query by query string without write where for every condition. Actually you just enter query string according to the principles of that package. Therefore the package will make every condition by the query string. If you want to write a custom query in the separated layer you can do it. You can set fields of your model to allow build queries by the query string. Note that the query string must be sync with the fields of your Model. Isn't great in your opinion !?. This package saves your time and your code in laravel project. Fortunately like package eloquent-filter is rare in &lt;a href="https://github.com/mehdi-fathi/eloquent-filter"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;

&lt;p&gt;1- Run the Composer command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composer require mehdi-fathi/eloquent-filter
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;2- Add eloquentFilter\ServiceProvider::class to provider app.php&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'providers' =&amp;gt; [
  /*
   * Package Service Providers...
   */
    eloquentFilter\ServiceProvider::class
],
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;3- Add Facade 'EloquentFilter' =&amp;gt; eloquentFilter\Facade\EloquentFilter::class to aliases app.php&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'alias' =&amp;gt; [
  /*
   * Facade alias...
   */
    'EloquentFilter' =&amp;gt; eloquentFilter\Facade\EloquentFilter::class,
],
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Just this the Elqouent Filter is ready for use.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;Add Filterable trait to your models and set fields that you will want a filter in the whitelist. You can override this method in your models.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;You can set &lt;code&gt;*&lt;/code&gt; char for filter in all fields as like below example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private static $whiteListFilter = ['*'];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Use in Controller
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Note that the Eloquent Filter by default using the query string or request data to make queries.&lt;br&gt;
Also, you can set the array to &lt;code&gt;filter&lt;/code&gt; method Model for making your own custom condition without query string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Note that you must unset your own param as perpage. Just you can set page param for paginate this param ignore from filter.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can ignore some request params by use of code it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User::ignoreRequest(['perpage'])-&amp;gt;filter()
            -&amp;gt;paginate(request()-&amp;gt;get('perpage'), ['*'], 'page');
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Call &lt;code&gt;ignoreRequest&lt;/code&gt; will ignore some requests that you don't want to use in conditions eloquent filter. &lt;br&gt;
For example perpage param will never be in the conditions eloquent filter. &lt;br&gt;
it's related to the paginate method. &lt;code&gt;page&lt;/code&gt; param ignore by default in the Eloquent filter.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Another example use of a filter eloquent filter.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User::filter()-&amp;gt;paginate();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Done it!&lt;/p&gt;
&lt;h3&gt;
  
  
  Simple Example
&lt;/h3&gt;

&lt;p&gt;You just pass the data blade form to query string or generate a query string in the controller method. For example:&lt;/p&gt;
&lt;h3&gt;
  
  
  Simple Where
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?email=mehdifathi.developer@gmail.com
SELECT ... WHERE ... email = 'mehdifathi.developer@gmail.com'

/users/list?first_name=mehdi&amp;amp;last_name=fathi
SELECT ... WHERE ... first_name = 'mehdi' AND last_name = 'fathi'

/users/list?username[]=ali&amp;amp;username[]=ali22&amp;amp;family=ahmadi
SELECT ... WHERE ... username = 'ali' OR username = 'ali22' AND family = 'ahmadi'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Where by operator
&lt;/h3&gt;

&lt;p&gt;You can set any operator MySQL in the query string.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?count_posts[operator]=&amp;gt;&amp;amp;count_posts[value]=35
SELECT ... WHERE ... count_posts &amp;gt; 35

/users/list?username[operator]=!=&amp;amp;username[value]=ali
SELECT ... WHERE ... username != 'ali'

/users/list?count_posts[operator]=&amp;lt;&amp;amp;count_posts[value]=25
SELECT ... WHERE ... count_posts &amp;lt; 25
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Where the nested relation Model (New feature version 2 🔥)
&lt;/h3&gt;

&lt;p&gt;You can set all nested relation in the query string just by the array query string. For example, the user model has a relation with posts. and posts table has a relation with orders. You can make query conditions by set 'posts[count_post]' and 'posts[orders][name]' in the query string. Just be careful you must set 'posts.count_post' and 'posts.orders.name' in the User model.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?posts[count_post]=876&amp;amp;username=mehdi

select * from "users" where exists 
         (select * from "posts" where 
         "posts"."user_id" = "users"."id" 
         and "posts"."count_post" = 876)
         and "username" = "mehdi"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The above example as the same code that you use without the eloquent filter. Check it under code&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$user = new User();
$builder = $user-&amp;gt;with('posts');
        $builder-&amp;gt;whereHas('posts', function ($q) {
            $q-&amp;gt;where('count_post', 876);
        })-&amp;gt;where('username','mehdi');
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Special Parameters
&lt;/h3&gt;

&lt;p&gt;You can set special parameters &lt;code&gt;limit&lt;/code&gt; and &lt;code&gt;orderBy&lt;/code&gt; in query string for make query by that.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?f_params[limit]=1
SELECT ... WHERE ... order by `id` desc limit 1 offset 0

/users/list?f_params[orderBy][field]=id&amp;amp;f_params[orderBy][type]=ASC
SELECT ... WHERE ... order by `id` ASC limit 10 offset 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Where between
&lt;/h3&gt;

&lt;p&gt;If you are going to make a query whereBetween. You must fill the keys &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; in the query string. you can set it on query string as you know.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?created_at[start]=2016/05/01&amp;amp;created_at[end]=2017/10/01
SELECT ... WHERE ... created_at BETWEEN '2016/05/01' AND '2017/10/01'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Advanced Where
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?count_posts[operator]=&amp;gt;&amp;amp;count_posts[value]=10&amp;amp;username[]=ali&amp;amp;username[]=mehdi&amp;amp;family=ahmadi&amp;amp;created_at[start]=2016/05/01&amp;amp;created_at[end]=2020/10/01
&amp;amp;f_params[orderBy][field]=id&amp;amp;f_params[orderBy][type]=ASC

select * from `users` where `count_posts` &amp;gt; 10 and `username` in ('ali', 'mehdi') and 
`family` = ahmadi and `created_at` between '2016/05/01' and '2020/10/01' order by 'id' asc limit 10 offset 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Just note that fields of query string be the same rows table database in &lt;code&gt;$whiteListFilter&lt;/code&gt; in your model or declare the method in your model as the override method. The overriding method can be considered custom query filter.&lt;/p&gt;
&lt;h3&gt;
  
  
  Custom query filter
&lt;/h3&gt;

&lt;p&gt;If you are going to make yourself a query filter you can do it easily. You just make a trait and use it on model:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Note that fields of query string be the same methods of a trait. Use the trait in your model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?username_like=a

select * from `users` where `username` like %a% order by `id` desc limit 10 offset 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can make every filter with eloquent-filter. If you think the eloquent-filter is useful so give a ⭐️ to that by click in the link&lt;br&gt;
&lt;a href="https://github.com/mehdi-fathi/eloquent-filter"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For more details check out &lt;a href="https://github.com/mehdi-fathi/eloquent-filter"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt; repository&lt;/p&gt;

&lt;p&gt;Good luck and thank you for sharing your valuable time with me. I hope the Eloquent Filter is useful for your code. If you have any idea or opinion I glade to know it.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>eloquent</category>
      <category>mysql</category>
      <category>eloquentfilter</category>
    </item>
    <item>
      <title>How to be a good developer</title>
      <dc:creator>Mehdi Fathi</dc:creator>
      <pubDate>Mon, 04 May 2020 17:37:01 +0000</pubDate>
      <link>https://dev.to/mehdifathi/how-to-be-a-good-developer-3c5p</link>
      <guid>https://dev.to/mehdifathi/how-to-be-a-good-developer-3c5p</guid>
      <description>&lt;p&gt;I want to talk about who is a good developer.I'm trying to say simply to you.&lt;/p&gt;

&lt;p&gt;The top advantages of developers are :&lt;/p&gt;

&lt;p&gt;-He was never disappointed in the working and life.&lt;/p&gt;

&lt;p&gt;-He's done any bugs in the code.&lt;/p&gt;

&lt;p&gt;-He's always searching for a new way for old problems.&lt;/p&gt;

&lt;p&gt;-Don't be too happy when your problem of code is done.becuase you feel knowing anything in the world of programming and you never try to learn new things.&lt;/p&gt;

&lt;p&gt;-Make a challenge for yourself.you can use GitHub to make a new repository and you will develop that.&lt;/p&gt;

&lt;p&gt;-less ask questions and more search on google.&lt;/p&gt;

</description>
      <category>developer</category>
      <category>programing</category>
      <category>php</category>
    </item>
    <item>
      <title>Making the advanced query filter with Eloquent Filter in Laravel</title>
      <dc:creator>Mehdi Fathi</dc:creator>
      <pubDate>Sun, 22 Dec 2019 16:32:11 +0000</pubDate>
      <link>https://dev.to/mehdifathi/making-the-advanced-query-filter-with-eloquent-filter-in-laravel-3m5l</link>
      <guid>https://dev.to/mehdifathi/making-the-advanced-query-filter-with-eloquent-filter-in-laravel-3m5l</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Have you ever experienced make an advanced search page in programming? if your answer is yes maybe you know this feature has many conditions to make a query database.Especially when you are using a relational DB as MySQL in your project at that time our task will getting hard. I was searching for it. Eventually, I found a clean way to implement this feature in the Laravel project.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the main problem?
&lt;/h2&gt;

&lt;p&gt;The main problem is that you will make many conditions for every situation. Writing a lot of terms will surely reduce the readability of your code and increase the possibility of make a mistake.&lt;br&gt;
Practical example:&lt;br&gt;
Suppose we want to get the list of the users with the requested parameters as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:8000/users/search?age_more_than=25&amp;amp;gender=male&amp;amp;created_at=25-09-2019
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The Request parameter will be as follows:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 
  'age_more_than' =&amp;gt; '24',
  'gender' =&amp;gt; 'male',
  'created_at' =&amp;gt; '25-09-2019',
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Implement this feature in &lt;code&gt;UsersController.php&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;We check out a condition for each request.&lt;/p&gt;

&lt;p&gt;In the future, if your project will need more filter requests at that time you should add many conditions to the above code. Imagine some of the queries may be advanced therefore your code to be like &lt;strong&gt;Monster&lt;/strong&gt;!&lt;/p&gt;

&lt;h1&gt;
  
  
  Discover away
&lt;/h1&gt;

&lt;p&gt;Everything began from just a tutorial video called &lt;code&gt;Eloquent Techniques&lt;/code&gt; in laracast. It was about a new way to make an advanced filter by use of the query string. It has to separate layer filters from controller and model. It made an Eloquent query by the use of a query string. Advanced Eloquent rescued the readability of your code by a filter class. It was very good but you had to make a method for every condition. It's boring for a creative developer. You don't have a dynamic query and you have to write many methods for per condition just in a separate layer.&lt;/p&gt;

&lt;h1&gt;
  
  
  Eloquent Filter is your solution
&lt;/h1&gt;

&lt;p&gt;Imagine you will install a package composer and make a query by query string without write where for every condition. Actually you just enter query string according to the principles of that package. Therefore the package will make every condition by the query string. If you want to write a custom query in the separated layer you can do it. You can set fields of your model to allow build queries by the query string. Note that the query string must be sync with the fields of your Model. Isn't great in your opinion !?. This package saves your time and your code. Fortunately like package eloquent-filter is rare in &lt;a href="https://github.com/mehdi-fathi/eloquent-filter"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;-NOTE THAT : we've released the Eloquent filter version 2 recently. We suggest to installing version 2 with the new features you can visit this link : &lt;a href="https://dev.to/mehdifathi/introduce-eloquent-filter-2-in-laravel-12g5"&gt;https://dev.to/mehdifathi/introduce-eloquent-filter-2-in-laravel-12g5&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;

&lt;p&gt;Run the Composer command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composer require mehdi-fathi/eloquent-filter:1.6.9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;Add Filterable trait to your models and set fields that you will want a filter in whitelist. You can override this method in your models.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;You can set &lt;code&gt;*&lt;/code&gt; char for filter in all fields as like below example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private static $whiteListFilter = ['*'];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Use in Controller
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Done it!&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple Example
&lt;/h3&gt;

&lt;p&gt;You just pass the data blade form to query string or generate a query string in the controller method. For example:&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple Where
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?email=mehdifathi.developer@gmail.com
SELECT ... WHERE ... email = 'mehdifathi.developer@gmail.com'

/users/list?first_name=mehdi&amp;amp;last_name=fathi
SELECT ... WHERE ... first_name = 'mehdi' AND last_name = 'fathi'

/users/list?username[]=ali&amp;amp;username[]=ali22&amp;amp;family=ahmadi
SELECT ... WHERE ... username = 'ali' OR username = 'ali22' AND family = 'ahmadi'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Where by operator
&lt;/h3&gt;

&lt;p&gt;You can set any operator MySQL in the query string.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?count_posts[operator]=&amp;gt;&amp;amp;count_posts[value]=35
SELECT ... WHERE ... count_posts &amp;gt; 35

/users/list?username[operator]=!=&amp;amp;username[value]=ali
SELECT ... WHERE ... username != 'ali'

/users/list?count_posts[operator]=&amp;lt;&amp;amp;count_posts[value]=25
SELECT ... WHERE ... count_posts &amp;lt; 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Special Parameters
&lt;/h3&gt;

&lt;p&gt;You can set special parameters &lt;code&gt;limit&lt;/code&gt; and &lt;code&gt;orderBy&lt;/code&gt; in query string for make query by that.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?f_params[limit]=1
SELECT ... WHERE ... order by `id` desc limit 1 offset 0

/users/list?f_params[orderBy][field]=id&amp;amp;f_params[orderBy][type]=ASC
SELECT ... WHERE ... order by `id` ASC limit 10 offset 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Where between
&lt;/h3&gt;

&lt;p&gt;If you are going to make a query whereBetween. You must fill the keys &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; in the query string. you can set it on query string as you know.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?created_at[start]=2016/05/01&amp;amp;created_at[end]=2017/10/01
SELECT ... WHERE ... created_at BETWEEN '2016/05/01' AND '2017/10/01'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Advanced Where
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?count_posts[operator]=&amp;gt;&amp;amp;count_posts[value]=10&amp;amp;username[]=ali&amp;amp;username[]=mehdi&amp;amp;family=ahmadi&amp;amp;created_at[start]=2016/05/01&amp;amp;created_at[end]=2020/10/01
&amp;amp;f_params[orderBy][field]=id&amp;amp;f_params[orderBy][type]=ASC

select * from `users` where `count_posts` &amp;gt; 10 and `username` in ('ali', 'mehdi') and 
`family` = ahmadi and `created_at` between '2016/05/01' and '2020/10/01' order by 'id' asc limit 10 offset 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Just note that fields of query string be the same rows table database in &lt;code&gt;$whiteListFilter&lt;/code&gt; in your model or declare the method in your model as the override method. The overriding method can be considered custom query filter.&lt;/p&gt;
&lt;h3&gt;
  
  
  Custom query filter
&lt;/h3&gt;

&lt;p&gt;If you are going to make yourself a query filter you can do it easily. You just make a trait and use it on model:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Note that fields of query string be the same methods of a trait. Use the trait in your model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/users/list?username_like=a

select * from `users` where `username` like %a% order by `id` desc limit 10 offset 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can make every filter with eloquent-filter. If you think the eloquent-filter is useful so give a ⭐️ to that by click in the link&lt;br&gt;
&lt;a href="https://github.com/mehdi-fathi/eloquent-filter"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For more details check out &lt;a href="https://github.com/mehdi-fathi/eloquent-filter"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt; repository&lt;/p&gt;

&lt;p&gt;Good luck and thank you for sharing your valuable time with me. I hope the Eloquent Filter is useful for your code. If you have any idea or opinion I glade to know it.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>eloquent</category>
      <category>mysql</category>
      <category>php</category>
    </item>
  </channel>
</rss>
