怎么在laravel中利用with动态添加where条件-创新互联
本篇文章为大家展示了怎么在laravel中利用with动态添加where条件,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

模型:
public function getCollect()
{
return $this->belongsTo('App\Components\Misc\Models\CollectCareerTalk', 'id', 'career_talk_id');
}
public function otherMethod()
{
return $this->belongsTo('App\Components\Misc\Models\OtherMethodModel', '主键', '外键');
}仓库:
$this->model->with(['getCollect' => function ($q) use ($user_id) {
$q->where('user_id', $user_id);
},
'otherMethod'])
->select('id', 'title')
->where([
'id' => 1
])
->first();注意:with可以连多个表(数组形式传参),没有动态条件的,可以直接讲模型方法名写到with的参数中,有动态条件的,写到闭包中
上述内容就是怎么在laravel中利用with动态添加where条件,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
本文名称:怎么在laravel中利用with动态添加where条件-创新互联
路径分享:http://www.jxjierui.cn/article/cdcedd.html


咨询
建站咨询
