mirror of
				https://github.com/cp6/my-idlers.git
				synced 2025-10-31 06:19:09 +00:00 
			
		
		
		
	
		
			
	
	
		
			34 lines
		
	
	
	
		
			925 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
		
		
			
		
	
	
			34 lines
		
	
	
	
		
			925 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
|  | <?php | ||
|  | 
 | ||
|  | namespace App\Console\Commands; | ||
|  | 
 | ||
|  | use Illuminate\Console\Command; | ||
|  | use Illuminate\Support\Facades\DB; | ||
|  | 
 | ||
|  | class CreateDatabaseCommand extends Command | ||
|  | { | ||
|  |     protected $signature = 'make:database {name}'; | ||
|  | 
 | ||
|  |     protected $description = 'Creates my_idlers database'; | ||
|  | 
 | ||
|  |     public function __construct() | ||
|  |     { | ||
|  |         parent::__construct(); | ||
|  |     } | ||
|  | 
 | ||
|  |     public function handle() | ||
|  |     { | ||
|  |         $schemaName = $this->argument('name') ?: config("database.connections.mysql.database"); | ||
|  |         $charset = config("database.connections.mysql.charset",'utf8mb4'); | ||
|  |         $collation = config("database.connections.mysql.collation",'utf8mb4_unicode_ci'); | ||
|  | 
 | ||
|  |         config(["database.connections.mysql.database" => null]); | ||
|  | 
 | ||
|  |         $query = "CREATE DATABASE IF NOT EXISTS $schemaName CHARACTER SET $charset COLLATE $collation;"; | ||
|  | 
 | ||
|  |         DB::statement($query); | ||
|  | 
 | ||
|  |         config(["database.connections.mysql.database" => $schemaName]); | ||
|  |     } | ||
|  | } |