The relation of users.id = service_provider_category.user_id and service_provider_category.category_id = category.id
CodePudding user response:
Yes
Assuming that you have 3 models: User, ServiceProviderCategory and Category.
You need to create the relation ServiceProviderCategory in the User Model and create another relation of Category in the ServiceProvider Model.
Then you can easily access the data of the Category table using the eloquent relations.
$user = User::where('conditions')->first();
and get Category table data as below
$categoryData = $user->ServiceProviderCategory->Category;
CodePudding user response:
Try this, assuming that you want to show the category data in service_provider_category
and assuming you're using Eloquent.
ServiceProviderCategory::with('category')->get();
This will show the category
data if there's an existing otherwise null
if none.