alijumaan / laravel-ecommerce

142 stars 71 forks source link

Laravel accesors could be used #16

Closed allanvobraun closed 3 years ago

allanvobraun commented 3 years ago

https://github.com/alijumaan/Laravel-Ecommerce/blob/42abb71ca559e8b06aad4c76a2fd22a13ed5bd84/app/Models/User.php#L72

It is possible to use the laravel Accesor syntax here and in other methods. So there is no need to invoke a function every time you need the value. This is completely optional, but I consider it a good practice ...

Reference: https://laravel.com/docs/8.x/eloquent-mutators#accessors-and-mutators

allanvobraun commented 3 years ago

Example:

public function getFullNameAttribute()  
{  
    return "{$this->first_name} {$this->last_name}";  
}  

Usage : $model->full_name

alijumaan commented 3 years ago

I agree with you