Eager loading not pulling relation model.
Hi, Im using Laravel 6. Our database was created with Zend so our model is a bit strange; I have to set the primary keys.
// Customer model
protected $table = 'customer';
protected $primaryKey = 'Customer_ID';
/**
* Get all appointments for the customer.
*/
public function appointments()
{
return $this->hasMany('App\Appointment');
}
Then for the appointments
protected $table = 'appointment';
protected $primaryKey = 'Appointment_ID';
/**
* Get the customer assigned to this appointment.
*/
public function customer()
{
return $this->belongsTo('App\Customer');
}
Now, in a controller:
$appointments = App\Appointment::with('customer')->take(5)->get();
return response()->json($appointments, 200);
The array has the appointments but customer is null:
{... Customer_ID: 1234, customer: null}
Any ideas? Thanks