select distinct id from (SELECT
distinct books.id,name
FROM
authors,books,store.favorites,writers,users
where
authors.writer_id = writers.id and
books.id = authors.product_id and
users.id=favorites.user_id and
books.id=favorites.product_id
order by name asc) as newval
有人可以将此sql语句转换为Eloquent ORM或Query Builder吗?
答案 0 :(得分:0)
您的查询看起来像
DB::table('authors')->distinct()->select('books.id')
->join('books', 'books.id', '=', 'authors.product_id')
->join('store.favorites', 'books.id', '=', 'favorites.product_id')
->join('writers', 'authors.writer_id', '=', 'writers.id')
->join('users', 'users.id', '=', 'favorites.user_id')
->orderBy('name', 'asc')
P.S。 Laravel提供了关于Eloquent ORM
的良好文档