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 
:: 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 
:: 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 :: php password_hash 
Php :: laravel env use other env variables 
Php ::  
Php :: laravel enable query log 
::  
::  
Php :: find_in_set in laravel 
Php :: :: in php 
Php :: drop column laravel migration 
Php :: how to develop package beside laravel project 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =