mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
init
This commit is contained in:
28
app/Console/Commands/CreateDatabaseCommand.php
Normal file
28
app/Console/Commands/CreateDatabaseCommand.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateDatabaseCommand extends Command
|
||||
{
|
||||
protected $signature = 'database:create';
|
||||
|
||||
protected $description = 'Create the database if it does not exist.';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$schemaName = config("database.connections.mysql.database");
|
||||
|
||||
config(["database.connections.mysql.database" => null]);
|
||||
|
||||
$query = "CREATE DATABASE IF NOT EXISTS $schemaName";
|
||||
|
||||
DB::statement($query);
|
||||
|
||||
config(["database.connections.mysql.database" => $schemaName]);
|
||||
|
||||
$this->info(sprintf("Database `%s` created successfully.", $schemaName));
|
||||
}
|
||||
}
|
26
app/Console/Commands/CreateUserCommand.php
Normal file
26
app/Console/Commands/CreateUserCommand.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateUserCommand extends Command
|
||||
{
|
||||
protected $signature = 'user:create {name} {email}';
|
||||
|
||||
protected $description = 'Create a new user';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$password = Str::random(20);
|
||||
User::create([
|
||||
'name' => $this->argument('name'),
|
||||
'email' => $this->argument('email'),
|
||||
'password' => bcrypt($password),
|
||||
]);
|
||||
|
||||
$this->info("User created with password: {$password}");
|
||||
}
|
||||
}
|
27
app/Console/Kernel.php
Normal file
27
app/Console/Kernel.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user