'how to make a orm query with a string
How to make a orm query with a string
User
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, SoftDeletes, HasRoles;
public function avatar(): MorphOne
{
return $this->morphOne(Resource::class, 'resource');
}
Resource model
class Resource extends CoreModel
{
protected $fillable = [
'additional_identifier',
'type',
'path_512',
'path_1024',
'path_original',
'resource'
];
protected $appends = ['url_original', 'url_1024', 'url_512'];
public function getUrl512Attribute(): ?string
{
return URL::to($this->attributes['path_512']);
}
I need make from string orm query look like $model->avatar->url_512
in this picture the same situation is shown with the string and in the usual case
$model->{"avatar->url_512"}
=> $model->avatar->url_512
Is it possible?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|