Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually register a user in Laravel

Is it possible to manually register a user (with artisan?) rather than via the auth registration page?

I only need a handful of user accounts and wondered if there's a way to create these without having to set up the registration controllers and views.

like image 299
Matt Ellis Avatar asked Mar 02 '16 17:03

Matt Ellis


People also ask

How do I add a user in Laravel?

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();


2 Answers

I think you want to do this once-off, so there is no need for something fancy like creating an Artisan command etc. I would suggest to simply use php artisan tinker (great tool!) and add the following commands per user:

$user = new App\User(); $user->password = Hash::make('the-password-of-choice'); $user->email = '[email protected]'; $user->name = 'My Name'; $user->save(); 
like image 162
Christoffer Tyrefors Avatar answered Oct 11 '22 02:10

Christoffer Tyrefors


This is an old post, but if anyone wants to do it with command line, in Laravel 5.*, this is an easy way:

php artisan tinker 

then type (replace with your data):

DB::table('users')->insert(['name'=>'MyUsername','email'=>'[email protected]','password'=>Hash::make('123456')]) 
like image 37
Diverti Avatar answered Oct 11 '22 03:10

Diverti