I have a model with attachOne relation
class Person extends Model
{
public $attachOne = [
'avatar' => \System\Models\File::class
];
}
In the componen, I get the Person model
public function getPerson()
{
$person = Person::where('slug', $this->slug)->first();
return $person;
}
I got all the Person information, except the related model avatar.
{{ person.avatar }}
returns null
I found that if I don’t use ::class in the model it works fine
class Person extends Model
{
public $attachOne = [
'avatar' => '\System\Models\File'
];
}
{{ person.avatar }}
returns all the avatar information (path, name_disk… etc)
Why is that?
And, It happens only for attaching files to the model. If I use ::class with my own models It works fine
class Person extends Model
{
public $attachOne = [
'School' => \Author\Plugin\Models\School::class
];
}
In both cases, the backend works fine. The issue is only when I’m trying to access the related model in php or twig section
Additional information:
If I use ::class in the attachOne relation, I need to get the person with specific relation
public function getPerson()
{
$person = Person::with('avatar)->where('slug', $this->slug)->first();
return $person;
}
but that is not the idea. The attach relation should be dynamic, just like when I don’t use ::class
Thanks for your help!
I’m using October v3