
Laravel create default admin user
Sometimes you have to create an admin account in a laravel application. You can create an account using register form in laravel or you can also create the account using seeder and tinker shell. You can also create a key value pair for extra column which exists in your users table
-
Create user using php artisan tinker command
//Run tinker shell using tinker command on terminal php artisan tinker //Just copy paste below code in tinker shell it will create a new user for you. //Create user using create method on user model User::create(['name'=>'admin', 'email'=>'[email protected]', 'email_verified_at'=> now(), 'password'=> bcrypt('adminpass')]);
0You can create a user using the tinker command in Laravel. You have to run the tinker command php artisan tinker to start the tinker shell after that you create a user using the create method on the user model. You can also pass additional columns and values in the script such as ‘role_id’=> 2.
-
Create user using seeder
// Create Seeder file using command php artisan make:seeder AdminUserSeeder //database\seeders\AdminUserSeeder.php <?php namespace Database\Seeders; use Illuminate\Database\Seeder; use App\Models\User; class AdminUserSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { User::create(['name'=>'admin', 'email'=>'[email protected]', 'email_verified_at'=> now(), 'password'=> bcrypt('adminpass')]); } } //database\seeders\DatabaseSeeder.php public function run() { $this->call([ AdminUserSeeder::class, ]); } //Command for database seeding php artisan db:seed --class=AdminUserSeeder
0You can create a new user using a database seeder in laravel. You have to create a seeder using php artisan make:seeder command. After that you can use your user create script in the run method in the created file under database\seeders directory, pass seeder class to DatabaseSeeder.php and run php artisan db:seed command.
Random Code Snippet Queries: Laravel
- Laravel upload file with original file name
- There are no commands defined in the "route:" namespace
- Permanently delete a record in laravel
- Delete records with relationship in laravel
- If condition in foreach loop in laravel
- How to pass variable from controller to model in Laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Create records using relationship in laravel
- Define variable and use in Laravel controller method
- How to get the id of last record from collection object in laravel view
- Get duplicate records in laravel
- Order by multiple columns in Laravel
- How to get images from AWS s3 and display in Laravel blade
- How to use more than one query scope in Laravel
- Laravel get count with where condition
- If no route matched route::fallback in laravel
- How to create new user without form submission in laravel
- How to upload image in laravel 8
- Retain selected value of select box in Laravel
- How to create controller in laravel
- How to check data inserted or deleted in pivot after toggle method
- SQLSTATE[42000]: Syntax error or access violation: 1055
- Laravel route redirect not working
- Laravel form request validation
- How to insert dynamic value to additional column in pivot table in laravel