There are table diagram Sellers table are main table. Services and Areas tables can contain multiple services and areas for spacific Seller. For this I use seller_services and sellerable Pivot table belongsToMany() relationship to access services and areas.
In Seller Model
public function services()
{
return $this->belongsToMany('App\Models\Service');
}
public function areas()
{
return $this->morphedByMany('App\Models\Area', 'sellerable');
}
In Service Model
public function sellers()
{
return $this->belongsToMany('App\Models\Seller');
}
In Area Model
public function sellers()
{
return $this->morphToMany('App\Models\Seller', 'sellerable');
}
**Now the problem is.... If I request any service and any area then I want to access those Seller who have those requested services and area. And get all seller who matched this both request. **
I try those....
$service_name = Service::where('slug', $request->service)->first();
$area = Area::findOrFail($request->area);
$sellers = $service_name->sellers;
$sellers = $area->sellers;
In Blade
@if ($sellers)
@foreach ($sellers as $seller)
{{$seller->name}}
@endforeach
@endif
And Also Try....
@if ($service_name)
@foreach ($service_name->sellers and $area_name->sellers as $seller)
{{$seller->name}}
@endforeach
@endif
but it this way we can't access sellers who has both request. I need to access sellers where service and area will match this seller records.