Support the ongoing development of Laravel.io →
posted 7 years ago
Eloquent
Last updated 1 year ago.
0

You need to select columns as


$posts = DB::table('posts')
                ->select('posts.created_at *') 
                ->where('thread_id', $id)
                ->leftJoin('users', 'users.id', '=', 'posts.user_id')
                ->orderBy('posts.created_at', 'asc')
                ->get();

0

->select('posts.created_at *') looks wrong

it should be

 ->select('posts.*') 

so you're selecting only the columns of the posts table

0

code stops at the view now. like one of you mentioned we are using "column as" but we don't call it anything?

as I said, I display the result in the view like this: @foreach(posts as post) post->created..., and now with the changed query how do I do it? the exception says undefined property in view...

Last updated 7 years ago.
0

Thanks for the help guys, I think I solved it with select but, so I wanna be cool and use Eloquent instead of the Query Builder, but does Eloquent support left join?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

muppbarn muppbarn Joined 29 Mar 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.