【发布时间】:2017-12-11 08:08:43
【问题描述】:
这是我的模型User.php
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name', 'email', 'password', 'cell_phone', 'province_id', 'city_id', 'job'
];
protected $hidden = [
'password', 'remember_token',
];
public function city()
{
return $this->belongsTo('City');
}
}
这是我的控制器的一部分:
$user_info = User::find(Auth::user()->id);
dd($user_info->city);
它抛出这个:
"未定义的类常量'city'"
我该如何解决这个问题?
表格结构:
// users
+----+--------+---------+----------
| id | name | city_id | ...
+----+--------+---------+----------
| 1 | Jack | 5 | ...
// city
+----+--------+
| id | name |
+----+--------+
| 1 | Tehran |
【问题讨论】:
标签: php mysql laravel eloquent relational-database