How to create new user in Laravel?

I think you make it too complicated. There is no need to make it this way. By default you have User model created and you should be able simple to create user this way:

$user = new User();
$user->username = 'something';
$user->password = Hash::make('userpassword');
$user->email = '[email protected]';
$user->save();

Maybe you wanted to achieve something more but I don't understand what you use so many methods here if you don't modify input or output here.


You are using create method (Mass Assignment) so it's not working because you have this:

// Only user_id is allowed to insert by create method
protected $fillable = ['user_id'];

Put this in your model instead of $fillable:

// Allow any field to be inserted
protected $guarded = [];

Also you may use the alternative:

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

Read more about Mass Assignment on Laravel website. While this may solve the issue but be aware of it. You may use this approach instead:

$user = new User;
$user->username = 'jhondoe';
// Set other fields ...
$user->save();