【发布时间】:2019-09-06 06:50:30
【问题描述】:
这个 mysql sql sn-p 的 laravel 等效 eloquent 查询生成器是什么:
select * from `posts` left join `user_post_interactions` on `posts`.`id` = `user_post_interactions`.`post_id` where `posts`.`user_id` = 10 and not (`user_post_interactions`.`interaction_name` = 'hide' and `user_post_interactions`.`user_id` = 10)
我正在做的是:
$this->posts()->leftJoin('user_post_interactions', 'posts.id', '=', 'user_post_interactions.post_id')
->where(function($q) {
$q->where('user_post_interactions.interaction_name', '<>', 'hide')
->where('user_post_interactions.user_id', '<>', 10);
});
但这并没有产生我预期的结果
【问题讨论】:
-
使用 whereRaw 更多细节laravel.com/docs/5.7/queries#raw-expressions
标签: sql laravel laravel-5 eloquent