Shift with red gradient lettering

Adopt attribute accessors/mutators

Premium
Laravel 8+
Experimental

Starting with Laravel 8, you may define an accessor and mutator using a single, non-prefixed method which returns an Illuminate\Database\Eloquent\Casts\Attribute.

Before

public function getFirstNameAttribute($value)
{
return ucfirst($value);
}
 
public function setFirstNameAttribute($value)
{
$this->attributes['first_name'] = strtolower($value);
}

After

protected function firstName(): Attribute
{
return new Attribute(
get: fn ($value) => ucfirst($value),
set: fn ($value) => strtolower($value),
);
}

← Back to the Workbench Tasks

Sign in with any of the following services to connect Shift with your Laravel project.


Don't use one of these services?

Temporarily push your project to a free, private repository on one of these cloud-based services or upgrade your project locally with Shift for Docker.