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();
->select('posts.created_at *') looks wrong
it should be
->select('posts.*')
so you're selecting only the columns of the posts table
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...
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?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community