laravel 查询生成器
链接:https://laravel.com/docs/5.5/queries#raw-expressions
laravel 5.5 链接:https://laravelacademy.org/post/8060.html
SELECT t.*,u.`name`
FROM template t
INNER JOIN `user` u
ON u.id = t.user_id
WHERE t.is_delete = 1
AND ( t.title LIKE "%abc%" or u.`name` LIKE "%abc%" )
在这基础上再分页
Template::join('user', 'template.user_id', '=', 'user.id')
->where('is_delete', 1)
->where(function ($query) {
$query->where('title', 'like', '%abc%')
->orWhere('user.name', 'like', '%abc%');
})->skip(一页显示的记录数*(当前页-1))->take(一页显示的记录数)
->get();
join 一个临时表
Post::join(DB::raw('(select * from users) c '),'c.id','=','post.user_id')->get()