Even a normal sql query has to be "worked up", many times the first attempt isn't correct. As an example see: https://laracasts.com/discuss/channels/eloquent/orderby-computed-related-attribute
Help to convert SQL query into Eloquent?
I don't find easy tutorials in order to create complex queries into a DataBase, and as I am facing problems with pagination, using a raw query into DataBase, I prefer to convert it into a Eloquent model, and make pagination a straightforward process.
There's the query I did so far:
$comments = DB::select( DB::raw(" SELECT users.name, users.surname, users.image, reviews.comment, reviews.comment_score FROM reviews JOIN users ON reviews.user_id = users.id WHERE reviews.business_id = :logged_business; ") ,array('logged_business' => $business_id,));
The last 'array' is a way to pass a variable through the query. I don't know doing on Eloquent such comparison of ForeingKeys with PrimaryKeys =( I'm feeling helpless.
Hope you can help me. Thanks a lot ! !
if you use my second suggestion
@foreach($reviews as $review)
reviewer {{ $review->user->name }}
review: {{ $review->comment}}
@endforeach
Please or to participate in this conversation.