Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel eager loading where clause

$query = ""    

if ($request->has('country'){
$query = Post::with("country")->whereHas("country",function($q) use($request){
    $q->where("name","=",$request->country);
})->get()
}else{
    $query = Post::with("country")->get();
}
Comment

laravel eager-loading with selected columns

$results = User::with([
	'country' => function ($query) {
		$query->select('id','name');
	},'posts' => function ($query) {
		$query->select('id','user_id','title');
	},'posts.attachments' => function ($query) {
		$query->select('id','post_id','type');
	}])->get(['id','country_id','name']);
Comment

PREVIOUS NEXT
Code Example
Php :: laravel create mode 
Php :: how to display the site tagline in wordpress 
Php :: laravel cache put array 
Php :: laravel set appends 
Php :: php check if query succeeded 
Php :: php artisan create controller inside folder 
Php :: create controller with model resources and request command in laravel 
Php :: file form validation codeigniter 
Php :: guzzle Request with POST files 
Php :: bindparam php 
Php :: php formData curl 
Php :: get post info in php 
Php :: img src php wordpress theme child 
Php :: check installed php modules in linux 
Php :: laravel return response view 
Php :: cakephp get sql query string 
Php :: diffinhours with minutes carbon 
Php :: centos 8 laravel permission denied 
Php :: string match percentage php 
Php :: share wordpress post on whatsapp without plugin 
Php :: laravel query foreach 
Php :: french special characters php 
Php :: get authinticated user id laravel 
Php :: laravel migration integer 
Php :: is replace case sensitive php 
Php :: basename in php 
Php :: PHP similar_text — Calculate the similarity between two strings 
Php :: php artisan route list does not show all my routes 
Php :: what does defined di in php 
Php :: check if date has passed php 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =