MINI Sh3ll
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
class Repositories extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:repository {modelName : The name of the model}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create repository for model';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$modelName = $this->argument('modelName');
if ($modelName === '' || is_null($modelName) || empty($modelName)) {
$this->error('Model Name Invalid..!');
} elseif (! File::exists('app/Models/'.$modelName.'.php')) {
$this->error('Model Not exists..!');
} elseif (! File::exists('app/Solar/Repositories/'.$modelName)) {
File::makeDirectory('app/Solar/Repositories/'.$modelName, 0775, true);
$interface = 'app/Solar/Repositories/' . $modelName . '/' .$modelName . 'Interface.php';
$repository = 'app/Solar/Repositories/' . $modelName . '/' .$modelName . 'Repository.php';
if (! File::exists($interface) && ! File::exists($repository)) {
$interfaceFileContent = "<?php\n\nnamespace App\\Solar\\Repositories\\".$modelName.";\n\n";
$interfaceFileContent.= "interface " . $modelName . "Interface\n{\n\n}\n";
File::put($interface, $interfaceFileContent);
$repositoryContent = "<?php\n\n";
$repositoryContent.= "namespace App\\Solar\\Repositories\\".$modelName.";\n\n";
$repositoryContent.= "use App\\Models\\".$modelName.";\n\n";
$repositoryContent.= "class " . $modelName . "Repository implements " . $modelName . "Interface\n{";
$repositoryContent.= "\n\t/**\n\t * @var ".$modelName."\n\t */";
$repositoryContent.= "\n\tprivate $".lcfirst($modelName).";\n\n";
$repositoryContent.= "\t/**\n\t * ".$modelName."Repository constructor.\n";
$repositoryContent.= "\t * @param ".$modelName." $".lcfirst($modelName)."\n\t */";
$repositoryContent.= "\n\tpublic function __construct(".$modelName." $".lcfirst($modelName).") {\n";
$repositoryContent.= "\t\t$"."this->".lcfirst($modelName)." = $".lcfirst($modelName).";"."\n";
$repositoryContent.= "\t}\n}\n";
File::put($repository, $repositoryContent);
$this->info("Repository Files Created Successfully.");
} else {
$this->error('Repository Files Already Exists.');
}
} else {
$this->error('Repository Already Exists.');
}
}
}
OHA YOOOO