【发布时间】:2017-08-04 19:58:05
【问题描述】:
我正在尝试获取与 tinker 的关系中的数据。我收到一条错误消息,提示找不到 Class 'App\Date'。我想是因为我没有使用正确的代码,但我不知道我需要什么代码。
我有 2 个模型:
联系人 (app\Models\Contact.php)
日期 (app\Models\Date.php)
联系方式
public function dates(){
return $this->hasMany(Date::class);
}
修补匠
php artisan tinker
$test = App\Models\Contact::find(516);
$test 返回一个用户。
如果我使用 $test->dates 之后我会收到一条错误消息:
[Symfony\Component\Debug\Exception\FatalErrorException]Class 'App\Date' not found
【问题讨论】:
-
请显示您的联系人型号。主要是关系部分。
-
关系部分已经显示,它的公共函数dates()
-
使用
return $this->hasMany(App\Models\Date, 'contact_id'); -
在你的关系中尝试完整的命名空间。
App\Models\Date::class