[英]Laravel: Eloquent / Tinker Class not found
I'm trying to get data in a relationship with tinker. 我正在尝试与修补匠建立关系。 I get an error that says Class 'App\\Date' not found.
我收到一条错误消息,提示未找到“ App \\ Date”类。 I think cause I am not using the right code, but I have no idea what code I need.
我认为是因为我没有使用正确的代码,但是我不知道我需要什么代码。
I have 2 models: 我有2个型号:
Contact (app\\Models\\Contact.php) 联系人(app \\ Models \\ Contact.php)
Date (app\\Models\\Date.php) 日期(app \\ Models \\ Date.php)
Contact 联系
public function dates(){
return $this->hasMany(Date::class);
}
Tinker 修补匠
php artisan tinker
$test = App\Models\Contact::find(516);
$test returns a user. $ test返回一个用户。
If I uses $test->dates after that I get an error saying this: 如果在此之后我使用$ test-> dates,则会出现错误消息:
[Symfony\Component\Debug\Exception\FatalErrorException]Class 'App\Date' not found
$test->dates
is most likely a relationship. $test->dates
很可能是一种关系。 In that relation, it's failing to find the class used in the relationship. 在该关系中,找不到该关系中使用的类。
public function dates(){
return $this->hasMany('App\Models\Date');
}
Make sure you're using correct namespace in the Date.php
, it should be namespace App\\Models;
确保在
Date.php
使用正确的命名空间,它应该是namespace App\\Models;
and not namespace App;
而不是
namespace App;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.