CourseWork/app/Console/Commands/AddAdmin.php

44 lines
871 B
PHP
Raw Normal View History

2024-06-23 17:02:18 +04:00
<?php
namespace App\Console\Commands;
use App\Models\Admin;
use App\Models\User;
use Illuminate\Console\Command;
class AddAdmin extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:add-admin';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create new admin';
/**
* Execute the console command.
*/
public function handle()
{
$admin = Admin::create();
$user = User::create([
'email' => 'admin' . $admin->id . '@mail',
'password' => 'password',
]);
$admin->user()->save($user);
$this->info('Admin created successfully!');
$this->info('email = ' . $user->email);
$this->info('password = password');
}
}