0
votes

I have two tables. One is user and the other is category, I have written this Eloquent ORM query to retrieves data from category

$category = Category::where(['status'=>'active'])->orderBy('id','asc')->get();

In category table here has a field called user_id. I want to join the user table and want to retrieve the user name where category table 'user_id' == user table 'id'.

How can I do this in Laravel eloquent ORM without Foreign key And Multiple models.

I don't know who voted this question as Opinion-based. But this question should not be opinion-based - sta
You can define a relation in your category model and specify user_id as the mapping attribute to load user with category - M Khalid Junaid