I've 3 models:
User: DB:
-id
...
Model:
public function orders() {
return $this->hasMany('App\Order');
}
public function billets() {
return $this->hasManyThrough(App\Billet', 'App\Order');
}
Order: DB:
-id
-user_id
...
Model:
public function user() {
return $this->belongsTo('App\User');
}
}
Billet: DB:
-id
-order_id
-url
...
Model:
public function order() {
return $this->belongsTo('App\Order');
}
}
Controller:
$orders = User::find($id)->orders;
$billets = User::find($id)->billets;
//
return view('my.view', compact('orders', 'billets'));
The problem:
I can't list $orders and $billets togethers using the same foreach on my view...
Separete works:
@foreach ($orders as $order)
{{ $order->name }}
@endforeach
//
@foreach ($billets as $billet)
{{ $billet->url }}
@endforeach
I needed something like:
@foreach ($orders as $order)
{{ $order->name }} {{ $order->billet->url }}
@endforeach
I need $order->name and billet->url together, associated...
Separate work. List all billets related to the user. But I can't associate the same foreach User + Billet + Order.
Any idea?
Thanks.
Yes. But didn't work because not all orders have a billet. So everything is messy... basically I need to access the billet (and their records) through the order and user (User->order->billet->url).
Thank you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community