Migrate to the new Model attributes syntax
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
- public function getFirstNameAttribute($value)
+ protected function firstName(): \Illuminate\Database\Eloquent\Casts\Attribute
{
- return ucfirst($value);
- }
-
- public function setFirstNameAttribute($value)
- {
- $this->attributes['first_name'] = strtolower($value);
- $this->attributes['first_name_upper'] = strtoupper($value);
+ return \Illuminate\Database\Eloquent\Casts\Attribute::make(get: function ($value) {
+ return ucfirst($value);
+ }, set: function ($value) {
+ return ['first_name' => strtolower($value), 'first_name_upper' => strtoupper($value)];
+ });
}
}
Configure your rector.php
:
<?php
use RectorLaravel\Rector\ClassMethod\MigrateToSimplifiedAttributeRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
MigrateToSimplifiedAttributeRector::class,
]);