lundi 29 avril 2019

Laravel 5.8 newing up eloquent model and calling accessor in one line?

I have a contact_info_scopes table and one of the scopes is 'Default', which is likely to be the most common scope called, so I'm creating an accessor

public function getDefaultScopeIdAttribute()
{
    return $this::where('contact_info_scope', 'Default')
        ->first()
        ->contact_info_scope_uuid;
}

to get the defaultScopeId and wondering how I can new up the ContactInfoScope model and access that in one line. I know I can new it up:

$contactInfoScope = new ContactInfoScope();

and then access it:

$contactInfoScope->defaultScopeId;

but I would like to do this in one line without having to store the class in a variable. Open to any other creative ways of tackling this as well! Thanks :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire