What is Accessor in Laravel?

By | June 18, 2020

As we know laravel accessor is very userful feature. It is used for creating the virtual attribute on the object which you want to access it as database column name.

So for example if you want to show full name and in your database table (users) has first_name and last_name columns, you can write:

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

Then you can call $user->full_name and it will return the first and last name collectively. Naming convention for accessor is a snake_case attribute, so getFullNameAttribute function would be accessible through $user->user_name.

prefix must be added as get and suffix would be Attribute

13 thoughts on “What is Accessor in Laravel?

  1. sikis izle

    Wow! Finally I got a website from where I can truly get helpful facts regarding my study and knowledge. Darb Flinn Malvie

  2. sikis izle

    Because the admin of this web page is working, no question very rapidly it will be well-known, due to its feature contents. Berenice Eli Colp

  3. yify

    My relatives all the time say that I am killing my time here at net, but I know I am getting knowledge all the time by reading thes pleasant content. Nicki Brig Dur

  4. I Fashion Styles

    Really Appreciate this article, is there any way I can receive an email sent to me whenever you make a new post?

  5. KAYSWELL

    It抯 laborious to search out educated people on this subject, however you sound like you understand what you抮e talking about! Thanks

  6. Hairstyles VIP

    Hey! Someone in my Myspace group shared this website with us so I came to look it over. I’m definitely enjoying the information. I’m book-marking and will be tweeting this to my followers! Fantastic blog and brilliant style and design.

  7. Hairstyles

    My brother suggested I may like this web site. He was totally right. This put up actually made my day. You can not consider simply how a lot time I had spent for this information! Thank you!

  8. KAYSWELL

    Thanks for another informative website. Where else could I get that type of information written in such an ideal way? I have a project that I am just now working on, and I’ve been on the look out for such information.

  9. Hairstyles VIP

    Oh my goodness! a tremendous article dude. Thank you Nonetheless I’m experiencing subject with ur rss . Don抰 know why Unable to subscribe to it. Is there anyone getting equivalent rss problem? Anyone who knows kindly respond. Thnkx

  10. I Fashion Styles

    whoah this blog is magnificent i love reading your articles. Keep up the good work! You know, a lot of people are searching around for this information, you can aid them greatly.

Leave a Reply