Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel wherehas

$users = User::whereHas('posts', function($q){
    $q->where('created_at', '>=', '2015-01-01 00:00:00');
})->get();
// only users that have posts from 2015 on forward are returned
Comment

laravel wherehas with condition

public function index()
{
    $countryName = 'Brazil';
    $users = User::with('country')
		->whereHas('country', function (Builder $query) use($countryName) {
			$query->where('name', 'like', "%{$countryName}%");
		})
      ->get();
}
Comment

wherehas laravel search

                ->whereHas('translation', function ($query) use ($name){
                    $query->where('name', 'like', $name);
                }, '>=', 10)
Comment

orwhere in wherehas laravel

User::select()->whereHas('student', $function($q) {
        $q->where('name', $value)
          ->orWhere('age', $value2);
    });
Comment

how to use whereHas in laravel

//https://laravel.com/docs/9.x/queries#conditional-clauses

$result = $query
    ->where('precedence', '=', $precedenceStatus)
    ->when($person, function ($query) use ($person) {
        $query->whereHas('personnel', fn ($q) => $q->where('id', '=', $person));
    })
    ->get();
Comment

PREVIOUS NEXT
Code Example
Php :: Problem 1 - phpspec/prophecy is locked to version 1.13.0 and an update of this package was not requested. - phpspec/prophecy 1.13.0 requires php ^7.2 || ~8.0, <8.1 - your php version (8.1.2) does not satisfy that requirement. 
Php :: HTML Snippets not working in .php files 
Php :: Limit Product Name in Magento2 
Php :: laravel get next record 
Php :: make model -mcr laravel 
Php :: laravel decrement 
Php :: run raw sql with doctrine manager 
Php :: Get color code from string 
Php :: laravel create migration add column 
Php :: read text from docx in php 
Php :: implode php 
Php :: wordpress get perma link 
Php :: php pass variable to anonymous function 
Php :: pass php variable in onclick function 
Php :: php get index of current item array_reduce 
Php :: sha256 php 
Php :: guzzle post request with data 
Php :: eloquent where in 
Php :: symfony request get all parameters 
Php :: laravel blade route redirect back 
Php :: laravel validate unique column 
Php :: rename migration in laravel 
Php :: mysql get the last id php 
Php :: nav active in laravel 
Php :: method put laravel 
Php :: check if number is multiple of 3 in php 
Php :: error repoerting in php 
Php :: php loop through list 
Php :: php shell script 
Php :: how to add script in WordPress admin page 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =