Find the best Rector rule to solve your problem. Searching through 671 rules.
Found 3 rules:
Replace $this->faker with the fake() helper function in Factories
class UserFactory extends Factory
{
public function definition()
{
return [
- 'name' => $this->faker->name,
- 'email' => $this->faker->unique()->safeEmail,
+ 'name' => fake()->name,
+ 'email' => fake()->unique()->safeEmail,
];
}
}
Adds the @extends annotation to Factories.
use Illuminate\Database\Eloquent\Factories\Factory;
+/**
+ * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
+ */
class UserFactory extends Factory
{
protected $model = \App\Models\User::class;
}
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)];
+ });
}
}