Laravel 5 - 没有为belongsTo显示任何关系

Lov*_*ock 1 php laravel eloquent laravel-5

自从我参与Laravel项目以来已经有一段时间了,并且无法理解为什么会出现这个问题.

我有一个'车辆'表和一个'客户'表.

在vehicles表中有一行,其字段'customer_id'的值为1.在'customers'表中还有一个id为1的客户.

在我的车辆模型中,我有:

public function customer()
{
    return $this->belongsTo('App\Customer');
}
Run Code Online (Sandbox Code Playgroud)

但是当从查询返回数据时:

$vehicle = Vehicle::find($id);
dd($vehicle);
Run Code Online (Sandbox Code Playgroud)

关系数组是空白的.

我在这个错误的地方?没有错误,只有没有数据.

Ale*_*nin 6

如果您想获得车辆的客户:

$vehicle = Vehicle::with('customer')->find($id);
Run Code Online (Sandbox Code Playgroud)

https://laravel.com/docs/5.4/eloquent-relationships#eager-loading