laravel requiring name in fillable array while it’s in it

Published

my problem is when I register a new user, after I submit the post request it throws an exception saying Add [name] to fillable property to allow mass assignment on [IlluminateFoundationAuthUser] and its already exist in fillable.

namespace AppHttpControllersAuth;

/*imports here*/

class SignupController extends Controller
{
    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required',
            'surname' => 'required',
            'username' => 'required|min:3|max:20',
            'phone' => 'required',
            'email' => 'required',
            'password' => 'required|confirmed',
        ]);

        User::create([
            'name'=> $request->name,
            'surname'=> $request->surname,
            'username'=> $request->username,
            'phone'=> $request->phone,
            'email'=> $request->email,
            'password'=> Hash::make($request->password),
        ]);
    }
}

and when I execute php artisan migrate, it throws

Migrating: 2022_01_14_124437_add_username_to_users_table

   Error

  Call to undefined method IlluminateDatabaseSchemaMySqlBuilder::dropColumnIfExists()

  at C:UsersxxgamOneDriveDesktopprojectsdenemevendorlaravelframeworksrcIlluminateSupportFacadesFacade.php:261
    257▕         if (! $instance) {
    258▕             throw new RuntimeException('A facade root has not been set.');
    259▕         }
    260▕
  ➜ 261▕         return $instance->$method(...$args);
    262▕     }
    263▕ }
    264▕

  1   C:UsersxxgamOneDriveDesktopprojectsdenemedatabasemigrations22_01_14_124437_add_username_to_users_table.php:16
      IlluminateSupportFacadesFacade::__callStatic("dropColumnIfExists")

  2   C:UsersxxgamOneDriveDesktopprojectsdenemevendorlaravelframeworksrcIlluminateDatabaseMigrationsMigrator.php:394
      AddUsernameToUsersTable::up()

C:UsersxxgamOneDriveDesktopprojectsdeneme>php artisan migrate:rollback
Rolling back: 2019_12_14_000001_create_personal_access_tokens_table
Rolled back:  2019_12_14_000001_create_personal_access_tokens_table (6.35ms)

C:UsersxxgamOneDriveDesktopprojectsdeneme>php artisan migrate
Migrating: 2019_12_14_000001_create_personal_access_tokens_table
Migrated:  2019_12_14_000001_create_personal_access_tokens_table (264.26ms)
Migrating: 2022_01_14_124437_add_username_to_users_table
Migrated:  2022_01_14_124437_add_username_to_users_table (115.22ms)

User Class

namespace AppModels;

use IlluminateContractsAuthMustVerifyEmail;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateFoundationAuthUser as Authenticatable;
use IlluminateNotificationsNotifiable;
use LaravelSanctumHasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;

    protected $fillable = [
        'name',
        'surname',
        'username',
        'phone',
        'email',
        'password',
    ];

    protected $hidden = [
        'password',
        'remember_token',
    ];

    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

I only know the basics in laravel, so if I missed something to write here tell me and I’ll write it.

Source: Laravel

Published
Categorised as authentication, laravel, model-view-controller, php Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq