Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel 8 model filter

<?php
  
$filters = EloquentFilters::make([
    new NameFilter($request->name)
]);
 
$products = Product::filter($filters)->get();


use PricecurrentLaravelEloquentFiltersAbstractEloquentFilter;
use IlluminateDatabaseEloquentBuilder;
 
class NameFilter extends AbstractEloquentFilter
{
    protected $name;
 
    public function __construct($name)
    {
        $this->name = $name;
    }
 
    public function apply(Builder $builder): Builder
    {
        return $query->where('name', 'like', "{$this->name}%");
    }
}

$filters = EloquentFilters::make([
    new NameFilter($request->user_name)
]);
 
$products = User::query()
    ->filter($filters)
    ->limit(10)
    ->latest()
    ->get();
Comment

PREVIOUS NEXT
Code Example
Php :: How to get a list of registered route paths in Laravel? 
Php :: append variable to string php 
Php :: php check if item in array 
Php :: Best documentation tools for php 
Php :: how to make trait in laravel 
Php :: laravel how to check app env 
Php :: php format phone number with dashes function 
Php :: laravel get current user id 
Php :: php get api 
Php :: php strftime year 2 digits 
Php :: wpquery search taxonomy 
Php :: php website templates free download with database 
Php :: month php written out 
Php :: check if any field update laravel 
Php :: unset method 
Php :: generate a unique id 
Php :: Laravel unique cheque using multiple column 
Php :: dependency injection php 
Php :: php crud generator 
Php :: install multiple php versions windows 
Php :: clear the compiled classes 
Php :: how to convert an array to uppercase before storing in database 
Php :: The Laravel installer requires PHP 7.3.0 or greater. Please use "composer create-project laravel/laravel" instead. 
Php :: yii2 oauth2 
Php :: php email sender 
Php :: php versions and features 
Php :: laravel eloquent relationships 
Php :: if php 
Php :: Redirect with named route in Laravel 
Php :: how to store wp editor in wordpress 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =