mirror of https://github.com/hasinhayder/hydra
parent
7a1e54be5c
commit
ca735f3f9a
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Modules;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BaseController extends Controller
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function transformResponse(string $message, $data = '', int $statusCode = Response::HTTP_OK): object
|
||||
{
|
||||
return response()->json((object)[
|
||||
|
||||
'statusCode' => $statusCode,
|
||||
'message' => $message,
|
||||
'data' => $data,
|
||||
|
||||
], $statusCode);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Modules;
|
||||
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BaseRepository
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Modules;
|
||||
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class BaseValidator
|
||||
{
|
||||
public static function validate(
|
||||
$data,
|
||||
$rules,
|
||||
$messages = [],
|
||||
$customAttributes = []
|
||||
) {
|
||||
$validator = Validator::make($data, $rules, $messages, $customAttributes);
|
||||
return $validator->validated();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
trait CommandTrait
|
||||
{
|
||||
protected function generateControllerFile($controllerName = null, $module = null, $ucModule = null, $underScoredName = null)
|
||||
{
|
||||
$controllerName = $controllerName ?? $this->module;
|
||||
$module = $module ?? $controllerName;
|
||||
$controllerStub = File::get(base_path("Modules/stubs/ControllerStub.stub"));
|
||||
$controllerPath = base_path($this->fromModule("Http/Controllers/{$controllerName}Controller.php"));
|
||||
$replaceModule = str_replace('{{module}}', $module, $controllerStub);
|
||||
$replaceClass = str_replace('{{class}}', $controllerName, $replaceModule);
|
||||
$replaceRepositoryName = str_replace('{{repoName}}', lcfirst($this->module), $replaceClass);
|
||||
$ucModuleReplace = str_replace('{{uCmodule}}', $ucModule, $replaceRepositoryName);
|
||||
$underScoreModuleReplace = str_replace('{{underscoreModule}}', strtolower($underScoredName), $ucModuleReplace);
|
||||
File::put($controllerPath, $underScoreModuleReplace);
|
||||
}
|
||||
|
||||
|
||||
public function fromModule($path)
|
||||
{
|
||||
return "Modules/{$this->module}/" . $path;
|
||||
}
|
||||
|
||||
public function generateRequest($controllerName, $module = null)
|
||||
{
|
||||
$controllerName = $controllerName ?? $this->module;
|
||||
$module = $module ?? $controllerName;
|
||||
|
||||
$requestStub = File::get(base_path("Modules/stubs/RequestsStub.stub"));
|
||||
$requestPath = base_path($this->fromModule("Http/Requests/{$controllerName}Request.php"));
|
||||
|
||||
$replaceModule = str_replace('{{module}}', $module, $requestStub);
|
||||
$replaceClass = str_replace('{{class}}', $controllerName, $replaceModule);
|
||||
|
||||
File::put($requestPath, $replaceClass);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class MakeController extends Command
|
||||
{
|
||||
|
||||
use CommandTrait;
|
||||
protected $namespace = "Modules";
|
||||
protected $servicePath;
|
||||
protected $modulePath;
|
||||
|
||||
private $module = null;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:controller {className} {--m|module=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Making module';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->module = trim($this->option('module'), "=");
|
||||
if (!$this->module) {
|
||||
$this->error("No module selected use -m or --module option to set module");
|
||||
return;
|
||||
}
|
||||
$className = $this->argument('className');
|
||||
|
||||
$this->generateControllerFile($className, $this->module);
|
||||
$this->info("Controller created successfully");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MakeMigration extends Command
|
||||
{
|
||||
|
||||
use CommandTrait;
|
||||
protected $namespace = "Modules";
|
||||
protected $servicePath;
|
||||
protected $modulePath;
|
||||
|
||||
private $module = null;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:migration {name} {--m|module=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Making module';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$module = trim($this->option('module'), "=");
|
||||
if (!$module) {
|
||||
$this->error("No module selected use -m or --module option to set module");
|
||||
return;
|
||||
}
|
||||
$className = $this->argument('name');
|
||||
$command = "make:migration {$className} --path=Modules/${module}/database/migrations";
|
||||
|
||||
Artisan::call($command);
|
||||
|
||||
$this->info($command);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class MakeRequest extends Command
|
||||
{
|
||||
|
||||
use CommandTrait;
|
||||
protected $namespace = "Modules";
|
||||
protected $servicePath;
|
||||
protected $modulePath;
|
||||
|
||||
private $module = null;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:request {className} {--m|module=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Making module';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->module = trim($this->option('module'), "=");
|
||||
if (!$this->module) {
|
||||
$this->error("No module selected use -m or --module option to set module");
|
||||
return;
|
||||
}
|
||||
$className = $this->argument('className');
|
||||
|
||||
$this->generateRequest($className, $this->module);
|
||||
$this->info("Controller created successfully");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use SebastianBergmann\Environment\Console;
|
||||
|
||||
class ModuleCommands extends Command
|
||||
{
|
||||
|
||||
use CommandTrait;
|
||||
protected $namespace = "Modules";
|
||||
protected $servicePath;
|
||||
protected $modulePath;
|
||||
|
||||
private $module = null;
|
||||
private $ucModule = null;
|
||||
private $lcModule = null;
|
||||
private $underScoredName = null;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'make:module {moduleName}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Making module';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
|
||||
// $this->ucModule =
|
||||
|
||||
// $this->moduleName = $this->argument('moduleName');
|
||||
// $this->namespace = 'Modules\\';
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->module = $this->argument('moduleName');
|
||||
$this->ucModule = lcfirst($this->argument('moduleName'));
|
||||
$this->lcModule = strtolower($this->argument('moduleName'));
|
||||
|
||||
// create undescored names
|
||||
$this->underScoredName = preg_replace('/([A-Z])/', "_$1", $this->ucModule);
|
||||
|
||||
|
||||
// Create module folder
|
||||
File::makeDirectory("Modules/{$this->module}");
|
||||
|
||||
$this->modulePath = $this->fromModule("");
|
||||
$this->generateServiceProvider();
|
||||
$this->generateModel();
|
||||
$this->generateDatabaseDir();
|
||||
$this->generateHttpDir();
|
||||
$this->generateRepository();
|
||||
$this->generateControllerFile($this->module, null, $this->ucModule, $this->underScoredName);
|
||||
$this->generateResources();
|
||||
$this->generateRoutes();
|
||||
$this->info($this->module . " extracted \n");
|
||||
return true;
|
||||
}
|
||||
|
||||
public function generateServiceProvider()
|
||||
{
|
||||
|
||||
// Get service provider stub
|
||||
$serviceProviderStub = base_path('Modules/stubs/serviceProvider.stub');
|
||||
// get stub contents
|
||||
$serviceProvider = File::get($serviceProviderStub);
|
||||
File::makeDirectory("Modules/{$this->module}/Providers");
|
||||
$this->servicePath = $this->getStubPath($this->module);
|
||||
File::put($this->servicePath, str_replace('{{module}}', $this->module, $serviceProvider));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function generateModel()
|
||||
{
|
||||
|
||||
// Get service provider stub
|
||||
$serviceProviderStub = base_path('Modules/stubs/Model.stub');
|
||||
// get stub contents
|
||||
$model = File::get($serviceProviderStub);
|
||||
File::makeDirectory("Modules/{$this->module}/Models");
|
||||
$this->servicePath = $this->modelPath($this->module);
|
||||
File::put($this->servicePath, str_replace('{{module}}', $this->module, $model));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function modelPath()
|
||||
{
|
||||
return base_path("Modules/{$this->module}/Models/{$this->module}.php");
|
||||
}
|
||||
|
||||
public function generateRepository()
|
||||
{
|
||||
|
||||
// Get service provider stub
|
||||
$repositoryStub = base_path('Modules/stubs/Repository.stub');
|
||||
// get stub contents
|
||||
$repository = File::get($repositoryStub);
|
||||
// File::makeDirectory("Modules/{$this->module}/Http");
|
||||
File::makeDirectory("Modules/{$this->module}/Http/Repositories");
|
||||
$this->servicePath = $this->repositoryPath($this->module);
|
||||
// name all module as variables
|
||||
$replaceRepovars = str_replace('{{uCmodule}}', $this->ucModule, $repository);
|
||||
// create all permission
|
||||
|
||||
$underScoredName = str_replace('{{underscoreModule}}', strtolower($this->underScoredName), $replaceRepovars);
|
||||
|
||||
$replacePermissions = str_replace('{{lcModule}}', $this->lcModule, $underScoredName);
|
||||
File::put($this->servicePath, str_replace('{{module}}', $this->module, $replacePermissions));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function repositoryPath()
|
||||
{
|
||||
return base_path("Modules/{$this->module}/Http/Repositories/{$this->module}Repository.php");
|
||||
}
|
||||
|
||||
protected function getStubPath()
|
||||
{
|
||||
return base_path("Modules/{$this->module}/Providers/{$this->module}ServiceProvider.php");
|
||||
}
|
||||
|
||||
|
||||
protected function generateDatabaseDir()
|
||||
{
|
||||
File::makeDirectory(base_path($this->fromModule("database")));
|
||||
File::makeDirectory(base_path($this->fromModule("database/migrations")));
|
||||
File::makeDirectory(base_path($this->fromModule("database/seeders")));
|
||||
File::makeDirectory(base_path($this->fromModule("database/fakers")));
|
||||
}
|
||||
|
||||
protected function generateHttpDir()
|
||||
{
|
||||
File::makeDirectory(base_path($this->fromModule("Http")));
|
||||
File::makeDirectory(base_path($this->fromModule("Http/Requests")));
|
||||
File::makeDirectory(base_path($this->fromModule("Http/Controllers")));
|
||||
}
|
||||
|
||||
protected function generateModelDir()
|
||||
{
|
||||
File::makeDirectory(base_path($this->fromModule("Model")));
|
||||
}
|
||||
|
||||
public function generateResources()
|
||||
{
|
||||
File::makeDirectory(base_path("Modules/{$this->module}/views"));
|
||||
}
|
||||
public function generateRoutes()
|
||||
{
|
||||
File::makeDirectory(base_path($this->fromModule("routes")));
|
||||
$apiRoutePath = $this->getRouthPath('api');
|
||||
|
||||
|
||||
$apiRouteStub = $this->getRouteStub('Api');
|
||||
$replaceModule = str_replace('{{module}}', $this->module, $apiRouteStub);
|
||||
$replaceLcModule = str_replace('{{lcModule}}', $this->lcModule, $replaceModule);
|
||||
|
||||
|
||||
File::put($apiRoutePath, $replaceLcModule);
|
||||
|
||||
$apiRoutePath = $this->getRouthPath('web');
|
||||
File::put($apiRoutePath, str_replace('{{module}}', $this->module, $this->getRouteStub('Web')));
|
||||
}
|
||||
|
||||
public function getRouthPath($type)
|
||||
{
|
||||
return base_path($this->fromModule("/routes/{$type}.php"));
|
||||
}
|
||||
|
||||
public function getRouteStub($type)
|
||||
{
|
||||
return File::get(base_path("Modules/stubs/{$type}RoutesStub.stub"));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Modules;
|
||||
|
||||
abstract class TransformResponse
|
||||
{
|
||||
public $statusCode;
|
||||
public $message;
|
||||
public $data;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register API routes for your application. These
|
||||
| routes are loaded by the RouteServiceProvider within a group which
|
||||
| is assigned the "api" middleware group. Enjoy building your API!
|
||||
|
|
||||
*/
|
||||
Route::group([
|
||||
'middleware' => ['auth:sanctum', /**"role:SuperAdmin"*/],
|
||||
'prefix' => 'api',
|
||||
"namespace" => "{{lcModule}}"
|
||||
], function () {
|
||||
|
||||
Route::post('/{{lcModule}}s', [{{module}}Controller::class, 'create{{module}}']);
|
||||
Route::get('/{{lcModule}}s', [{{module}}Controller::class, 'get{{module}}s']);
|
||||
Route::get('/{{lcModule}}s/{{{lcModule}}Id}', [{{module}}Controller::class, 'get{{module}}']);
|
||||
Route::post('/{{lcModule}}s/edit', [{{module}}Controller::class, 'edit{{module}}']);
|
||||
Route::delete('/{{lcModule}}s/{{{lcModule}}Id}', [{{module}}Controller::class, 'delete{{module}}']);
|
||||
|
||||
});
|
||||
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\{{module}}\Http\Controllers;
|
||||
|
||||
use Modules\BaseController;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\{{module}}\Http\Repositories\{{module}}Repository;
|
||||
class {{class}}Controller extends BaseController
|
||||
{
|
||||
public function __construct(private {{module}}Repository ${{repoName}}Repository){
|
||||
|
||||
}
|
||||
|
||||
public function create{{module}}(Request $request){
|
||||
$request->validate([
|
||||
// 'name' => "required|string"
|
||||
]);
|
||||
|
||||
$created{{module}} = $this->{{repoName}}Repository->create{{module}}($request->all());
|
||||
|
||||
return $this->transformResponse('{{module}} created Successfully', ["{{repoName}}" => $created{{module}}]);
|
||||
|
||||
}
|
||||
|
||||
public function get{{module}}s(Request $request){
|
||||
|
||||
${{repoName}}s = $this->{{repoName}}Repository->get{{module}}s($request->all());
|
||||
|
||||
return $this->transformResponse('{{module}}s Fetched Successfully', ["{{repoName}}" => ${{repoName}}s]);
|
||||
|
||||
}
|
||||
|
||||
public function get{{module}}(${{repoName}}Id){
|
||||
|
||||
${{repoName}} = $this->{{repoName}}Repository->get{{module}}(${{repoName}}Id);
|
||||
|
||||
return $this->transformResponse('{{module}} Fetched Successfully', ["{{repoName}}" => ${{repoName}}]);
|
||||
|
||||
}
|
||||
|
||||
public function edit{{module}}(Request $request){
|
||||
$request->validate([
|
||||
"{{underscoreModule}}_id" => "required|exists:table,id"
|
||||
]);
|
||||
|
||||
${{module}} = $this->{{repoName}}Repository->edit{{module}}($request->all());
|
||||
|
||||
return $this->transformResponse('{{module}} edited Successfully', ["{{repoName}}" => ${{module}}]);
|
||||
}
|
||||
|
||||
public function delete{{module}}(${{uCmodule}}Id){
|
||||
|
||||
${{module}} = $this->{{repoName}}Repository->delete{{module}}(${{uCmodule}}Id);
|
||||
|
||||
return $this->transformResponse('{{module}} deleted Successfully', ["{{repoName}}" => ${{module}}]);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class {{ class }} extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('{{ table }}', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('{{ table }}');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class {{ class }} extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\{{module}}\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class {{module}} extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\{{module}}\Http\Repositories;
|
||||
|
||||
use Modules\{{module}}\Models\{{module}};
|
||||
|
||||
class {{module}}Repository
|
||||
{
|
||||
|
||||
public function create{{module}}($data){
|
||||
|
||||
${{uCmodule}} = {{module}}::create([
|
||||
// 'name' => $data['name'],
|
||||
]);
|
||||
|
||||
return ${{uCmodule}};
|
||||
}
|
||||
|
||||
public function get{{module}}s($data){
|
||||
|
||||
if (!empty($data['search'])) {
|
||||
${{uCmodule}}s = {{module}}::where('name', 'like', "%{$data['search']}%")->orderBy('id', 'desc')->paginate(10);
|
||||
} else {
|
||||
${{uCmodule}}s = {{module}}::orderBy('id', 'desc')->paginate(10);
|
||||
}
|
||||
|
||||
return ${{uCmodule}}s;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function get{{module}}(int ${{uCmodule}}Id)
|
||||
{
|
||||
${{uCmodule}} = {{module}}::findOrFail(${{uCmodule}}Id);
|
||||
|
||||
return ${{uCmodule}};
|
||||
}
|
||||
|
||||
|
||||
public function edit{{module}}($data){
|
||||
|
||||
${{uCmodule}} = {{module}}::findOrFail($data['{{underscoreModule}}_id']);
|
||||
|
||||
${{uCmodule}}->save();
|
||||
return ${{uCmodule}};
|
||||
|
||||
}
|
||||
|
||||
public function delete{{module}}(${{underscoreModule}}Id){
|
||||
${{uCmodule}} = {{module}}::findOrFail(${{underscoreModule}}Id);
|
||||
${{uCmodule}}->delete();
|
||||
return ${{uCmodule}};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\{{module}}\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class {{class}}Request extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class {{ class }} extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('{{ table }}', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('{{ table }}', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Web Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register web routes for your application. These
|
||||
| routes are loaded by the RouteServiceProvider within a group which
|
||||
| contains the "web" middleware group. Now create something great!
|
||||
|
|
||||
*/
|
||||
|
||||
Route::get('/{{module}}', function () {
|
||||
return view('{{module}}');
|
||||
});
|
||||
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\{{module}}\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class {{module}}ServiceProvider extends BaseServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The controller namespace for the application.
|
||||
*
|
||||
* When present, controller route declarations will automatically be prefixed with this namespace.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $namespace = '\Modules\\{{module}}\\Http\\Controllers';
|
||||
|
||||
|
||||
|
||||
public function boot(){
|
||||
// Load {{module}} migrations from
|
||||
$this->loadMigrationsFrom(__DIR__."/../database/migrations");
|
||||
|
||||
// Load Views
|
||||
|
||||
$this->loadViewsFrom(__DIR__."/../views", strtolower('{{module}}'));
|
||||
|
||||
// // Load Routets
|
||||
$this->loadRoutesFrom(__DIR__."/../routes/web.php");
|
||||
$this->loadRoutesFrom(__DIR__ . "/../routes/api.php");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,297 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Composer;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class AppName extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'app:name';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Set the application namespace';
|
||||
|
||||
/**
|
||||
* The Composer class instance.
|
||||
*
|
||||
* @var \Illuminate\Support\Composer
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* Current root application namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $currentRoot;
|
||||
|
||||
/**
|
||||
* Create a new key generator command.
|
||||
*
|
||||
* @param \Illuminate\Support\Composer $composer
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Composer $composer, Filesystem $files)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->files = $files;
|
||||
$this->composer = $composer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->currentRoot = trim($this->laravel->getNamespace(), '\\');
|
||||
|
||||
$this->setAppDirectoryNamespace();
|
||||
$this->setBootstrapNamespaces();
|
||||
$this->setConfigNamespaces();
|
||||
$this->setComposerNamespace();
|
||||
$this->setDatabaseFactoryNamespaces();
|
||||
|
||||
$this->info('Application namespace set!');
|
||||
|
||||
$this->composer->dumpAutoloads();
|
||||
|
||||
$this->call('optimize:clear');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the namespace on the files in the app directory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setAppDirectoryNamespace()
|
||||
{
|
||||
$files = Finder::create()
|
||||
->in($this->laravel['path'])
|
||||
->contains($this->currentRoot)
|
||||
->name('*.php');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$this->replaceNamespace($file->getRealPath());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the App namespace at the given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
protected function replaceNamespace($path)
|
||||
{
|
||||
$search = [
|
||||
'namespace ' . $this->currentRoot . ';',
|
||||
$this->currentRoot . '\\',
|
||||
];
|
||||
|
||||
$replace = [
|
||||
'namespace ' . $this->argument('name') . ';',
|
||||
$this->argument('name') . '\\',
|
||||
];
|
||||
|
||||
$this->replaceIn($path, $search, $replace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bootstrap namespaces.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setBootstrapNamespaces()
|
||||
{
|
||||
$search = [
|
||||
$this->currentRoot . '\\Http',
|
||||
$this->currentRoot . '\\Console',
|
||||
$this->currentRoot . '\\Exceptions',
|
||||
];
|
||||
|
||||
$replace = [
|
||||
$this->argument('name') . '\\Http',
|
||||
$this->argument('name') . '\\Console',
|
||||
$this->argument('name') . '\\Exceptions',
|
||||
];
|
||||
|
||||
$this->replaceIn($this->getBootstrapPath(), $search, $replace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the namespace in the appropriate configuration files.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setConfigNamespaces()
|
||||
{
|
||||
$this->setAppConfigNamespaces();
|
||||
$this->setAuthConfigNamespace();
|
||||
$this->setServicesConfigNamespace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the application provider namespaces.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setAppConfigNamespaces()
|
||||
{
|
||||
$search = [
|
||||
$this->currentRoot . '\\Providers',
|
||||
$this->currentRoot . '\\Http\\Controllers\\',
|
||||
];
|
||||
|
||||
$replace = [
|
||||
$this->argument('name') . '\\Providers',
|
||||
$this->argument('name') . '\\Http\\Controllers\\',
|
||||
];
|
||||
|
||||
$this->replaceIn($this->getConfigPath('app'), $search, $replace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the authentication User namespace.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setAuthConfigNamespace()
|
||||
{
|
||||
$this->replaceIn(
|
||||
$this->getConfigPath('auth'),
|
||||
$this->currentRoot . '\\User',
|
||||
$this->argument('name') . '\\User'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the services User namespace.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setServicesConfigNamespace()
|
||||
{
|
||||
$this->replaceIn(
|
||||
$this->getConfigPath('services'),
|
||||
$this->currentRoot . '\\User',
|
||||
$this->argument('name') . '\\User'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the PSR-4 namespace in the Composer file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setComposerNamespace()
|
||||
{
|
||||
$this->replaceIn(
|
||||
$this->getComposerPath(),
|
||||
str_replace('\\', '\\\\', $this->currentRoot) . '\\\\',
|
||||
str_replace('\\', '\\\\', $this->argument('name')) . '\\\\'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the namespace in database factory files.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setDatabaseFactoryNamespaces()
|
||||
{
|
||||
$files = Finder::create()
|
||||
->in(database_path('factories'))
|
||||
->contains($this->currentRoot)
|
||||
->name('*.php');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$this->replaceIn(
|
||||
$file->getRealPath(),
|
||||
$this->currentRoot,
|
||||
$this->argument('name')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the given string in the given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|array $search
|
||||
* @param string|array $replace
|
||||
* @return void
|
||||
*/
|
||||
protected function replaceIn($path, $search, $replace)
|
||||
{
|
||||
if ($this->files->exists($path)) {
|
||||
$this->files->put($path, str_replace($search, $replace, $this->files->get($path)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the bootstrap/app.php file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getBootstrapPath()
|
||||
{
|
||||
return $this->laravel->bootstrapPath() . '/app.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the Composer.json file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getComposerPath()
|
||||
{
|
||||
return base_path('composer.json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the given configuration file.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function getConfigPath($name)
|
||||
{
|
||||
return $this->laravel['path.config'] . '/' . $name . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The desired namespace'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue