php artisan make:command CreateSuperUser
Open app/Console/Commands/CreateSuperUser.php
and insert
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Laravel\Spark\Spark;
class CreateSuperUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'super-user:create';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create admin user';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (env('SUPERUSER_NAME', false) && env('SUPERUSER_EMAIL', false) && env('SUPERUSER_PASSWORD', false)) {
$name = env('SUPERUSER_NAME');
$email = env('SUPERUSER_EMAIL');
$password = env('SUPERUSER_PASSWORD');
} else {
$name = env('SUPERUSER_NAME', $this->ask('Name'));
$email = env('SUPERUSER_EMAIL', $this->ask('E-mail'));
$password = env('SUPERUSER_PASSWORD', $this->secret('Password'));
$confirm = env('SUPERUSER_PASSWORD', $this->secret('Confirm password'));
if ($password !== $confirm) {
$this->error('ERROR: Password and confirmation do not match');
return false;
}
}
if (strlen($password) < 6) {
$this->error('ERROR: The password at least 6 characters');
return false;
}
Spark::user()
->forceFill(
[
'name' => $name,
'email' => $email,
'password' => bcrypt($password),
]
)
->save();
$this->info('The superuser is created!');
}
}
Open app/Console/Kernel.php
find $commands
array and append our command class
protected $commands = [
Commands\CreateSuperUser::class
];
routes/web.php
Route::any('/register', function(){
return redirect()
->to('/login', 302)
->with('status', 'Registration disabled.');
});