DEV Community

Cover image for Laravel Eloquent Mutators and Accessors
Bhanu Pratap Singh
Bhanu Pratap Singh

Posted on

Laravel Eloquent Mutators and Accessors

@Coderuck
Laravel Eloquent Mutators and Accessors allows you to transform Eloquent attribute values when you retrieve or set them on model instances.

Laravel Eloquent Mutators and Accessors is of the Eloquent ORM in the Laravel web framework.

In Laravel, mutators and accessors allow you to alter data before it's saved to and fetched from a database.

Basically through mutators you can alter data before it saved to database and through accessor allows you to alter data after it's fetched from a database. To define an accessor, create a get{Attribute}Attribute method on your model where {Attribute} will be your table column name will be like for example you have first_name as column name then it accessors will be getFirstNameAttribute() and mutators will be setFirstNameAttribute().

IMAGE ALT TEXT HERE

@Coderuck

Top comments (0)