![](/img/trans.png)
[英]Laravel 5.1 Applying Eloquent Relationships to Models Throws Class Not Found in Tinker
[英]Laravel: Eloquent / Tinker Class not found
我正在尝试与修补匠建立关系。 我收到一条错误消息,提示未找到“ 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
$test->dates
很可能是一种关系。 在该关系中,找不到该关系中使用的类。
public function dates(){
return $this->hasMany('App\Models\Date');
}
确保在Date.php
使用正确的命名空间,它应该是namespace App\\Models;
而不是namespace App;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.