Your query is right it's just you aren't fetching the data after joining the two tables.
You simply have to use first()
method at the end to retrieve the final result as shown below:
$post = Posts::select (
"posts.id",
"posts.description",
"posts.body",
"catergories.name as category_name"
)
->leftJoin("catergories", "posts.category_id", "=", "catergories.id")
->where('posts.id', $id)
->first();
dd($post->category_name);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community