'Eloquent in laravel route
i am trying to return data of the Staff , Staff_shops and Shop class in a route in order to get what shop that specific staff working on. I am trying to call by using eloquent
below is from Staff class
public function Staff_shop()
{
return $this->belongsTo(
Staff_shop::class, 'user_id');
}
below is from Shop class
public function Staff_shop()
{
return $this->belongsToMany(
Staff_shop::class, 'shop_id');
}
and below is from the Staff_shop class . Staff_shop is the bridge between Staff and Shop model
public function shop()
{
return $this->hasOne(Shop::class);
}
public function staff()
{
return $this->hasOne(Staff::class);
}
how i can write the correct way in this route below to dd()
Route::get('/testStaffShop', function () {
dd( ... );
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
