Accessors & Mutators

What is accessors

Accessors also called getters are used to format data when you retrieve them from the database.

What is mutators

Mutators also called setters are used to change data before saving data inside the if you want all your emails in your database to be lowercase only, you could do:


namespace App;

use Illuminate\Database\Eloquent\Model;

class todo extends Model
	/* Accessor */
	public function getNameAttribute($value){
		return ucfirst($value);

	/* Mutator */
	public function setEmailAttribute($value)
		$this->attributes['email'] = strtolower($value);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s