0
starting this topic by saying that I’m new to Laravel, but come on, I’m having a problem with Collection, is giving an error saying that it does not exist and that I made this connection in the Model as shown below.
Order Controller
public function index()
{
$customer = Customer::all();
$orders = $customer->orders()->get();
return view('admin.orders.index', compact('orders'));
}
Customer Model
public function orders()
{
return $this->hasMany(Order::class);
}
Order Model
public function customer()
{
return $this->belongsTo(Customer::class);
}
So Pedro, I’m trying to bring the information of the Orders, that together with him has a customer, in the way you showed, he only brings information of the customers and no information of the order. It would be better if I bring the order information and then pull the customer?
– Alexandre Xavier
I ended up doing it backwards and it worked, $Orders = $this->order->paginate(10); $Orders = $Orders->load('Customer');
– Alexandre Xavier