use with Time
with() The method is to use “ Eager loading ” Of , That mainly means ,laravel The exact association will be preloaded with the main model . This is very helpful for all the relationships that you want to add to a model . because “ Eager loading ” Relieved 1+N Query questions of , Just 1+1 One query will solve the problem , The query speed has been improved qualitatively . Support filter conditions
$groupInfo =
$this->class::where('site_id',$id)->with(['group'=>function($query){
$query->where('group_is_delete', 0); }])->get();
use has Time
has() The method is to filter the query results of the model based on the association relationship , So its function and function are different where The conditions are very similar . If you only use has(‘site’), That means you just want the model , There is at least one of these models post The relationship between the two .
$user = User::has('site.site_id', ‘>’, '3')->get();
use wherehas Time whereHas() The principle and basic principle of the method are introduced has() The method is the same , But it allows you to add your own filter to the model .
$users = User::whereHas('site', function($q){ $q->where('site_created_at',
'>=', '2019-08-12'); })->get(); // Returns only the user's post Recorded in 2019 year 08 month 12 Data after

Technology