|
|
|
@@ -0,0 +1,80 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace App\Console\Commands\Test; |
|
|
|
|
|
|
|
use App\Codes\UserRole; |
|
|
|
use App\Console\Commands\BaseCommand; |
|
|
|
use App\Models\User; |
|
|
|
use App\Util\DBUtil; |
|
|
|
use Exception; |
|
|
|
use Illuminate\Support\Facades\Hash; |
|
|
|
|
|
|
|
class 管理者ユーザー登録 extends BaseCommand |
|
|
|
{ |
|
|
|
|
|
|
|
const COMMAND = "test:make-admin-user"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* The name and signature of the console command. |
|
|
|
* |
|
|
|
* @var string |
|
|
|
*/ |
|
|
|
protected $signature = self::COMMAND; |
|
|
|
|
|
|
|
/** |
|
|
|
* The console command description. |
|
|
|
* |
|
|
|
* @var string |
|
|
|
*/ |
|
|
|
protected $description = '管理者ユーザーを登録する'; |
|
|
|
|
|
|
|
static public function getCommand() |
|
|
|
{ |
|
|
|
return self::COMMAND; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Create a new command instance. |
|
|
|
* |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public function __construct() |
|
|
|
{ |
|
|
|
parent::__construct(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Execute the console command. |
|
|
|
* |
|
|
|
* @return int |
|
|
|
*/ |
|
|
|
public function service(): int |
|
|
|
{ |
|
|
|
$db = new DBUtil(); |
|
|
|
try { |
|
|
|
$db->beginTransaction(); |
|
|
|
|
|
|
|
// 管理者ログインユーザーの作成 |
|
|
|
|
|
|
|
$user = User::whereEmail("admin@aa.com") |
|
|
|
->firstOrNew(); |
|
|
|
|
|
|
|
$user->name = "管理者"; |
|
|
|
$user->email = "admin@aa.com"; |
|
|
|
$user->role = UserRole::ADMIN; |
|
|
|
// $user->password = Hash::make("testuser"); |
|
|
|
$user->password = "testuser"; |
|
|
|
$user->save(); |
|
|
|
|
|
|
|
$db->commit(); |
|
|
|
} catch (Exception $e) { |
|
|
|
$db->rollBack(); |
|
|
|
throw $e; |
|
|
|
} |
|
|
|
|
|
|
|
return self::RESULTCODE_SUCCESS; |
|
|
|
} |
|
|
|
} |