I'm trying to get data in a relationship with tinker. I get an error that says Class 'App\\Date' not found. I think cause I am not using the right code, but I have no idea what code I need.
I have 2 models:
Contact (app\\Models\\Contact.php)
Date (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.
If I uses $test->dates after that I get an error saying this:
[Symfony\Component\Debug\Exception\FatalErrorException]Class 'App\Date' not found
$test->dates
is most likely a relationship. 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;
and not namespace App;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.