i have function ini my controller like this :
public function get_user_order()
{
$user = auth()->user()->orders()->with('products')->get();
$order = $user->products->name;
dd($order);
}
i want to get logged in user order history.
this is my user model:
class User extends \TCG\Voyager\Models\User
{
public function orders()
{
return $this->hasMany('App\Order');
}
}
this is my order model :
class Order extends Model
{
public function user()
{
return $this->belongsTo('App\User');
}
public function products()
{
return $this->belongsToMany('App\Product')->withPivot('quantity');
}
}
the problem is how can u get the product name from this relation ? please help me im newb, sorry for my broken english.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31mHCsC
via IFTTT
Aucun commentaire:
Enregistrer un commentaire