diff --git a/app/Console/Commands/MakeDatatable.php b/app/Console/Commands/MakeDatatable.php new file mode 100644 index 000000000000..6687f383e8ac --- /dev/null +++ b/app/Console/Commands/MakeDatatable.php @@ -0,0 +1,68 @@ +laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub('/datatable.stub', [ + 'NAMESPACE' => $this->getClassNamespace($module) . "\\" . config('modules.paths.generator.datatables'), + 'LOWER_NAME' => $module->getLowerName(), + 'CLASS' => $this->getClass(), + ]))->render(); + } + + public function getDestinationFilePath() + { + $path = $this->laravel['modules']->getModulePath($this->getModuleName()); + $seederPath = $this->laravel['modules']->config('paths.generator.datatables'); + + return $path . $seederPath . '/' . $this->getFileName() . '.php'; + } + + /** + * @return string + */ + protected function getFileName() + { + return studly_case($this->argument('name')) . 'Datatable'; + } + +} diff --git a/app/Console/Commands/MakeModule.php b/app/Console/Commands/MakeModule.php new file mode 100644 index 000000000000..a2a513fa19a3 --- /dev/null +++ b/app/Console/Commands/MakeModule.php @@ -0,0 +1,61 @@ +argument('name'); + $fields = $this->argument('fields'); + + $this->info("Creating module: {$name}"); + $this->info("Fields: {$fields}"); + + Artisan::call('module:make', ['name' => [$name]]); + Artisan::call('module:make-migration', ['name' => "create_{$name}_table", '--fields' => $fields, 'module' => $name]); + Artisan::call('module:make-model', ['model' => $name, 'module' => $name]); + + Artisan::call('ninja:make-datatable', ['name' => $name, 'module' => $name]); + } + + protected function getArguments() + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the module.'], + ['fields', InputArgument::OPTIONAL, 'The fields of the module.'] + ]; + } +} diff --git a/app/Console/Commands/stubs/command.stub b/app/Console/Commands/stubs/command.stub new file mode 100755 index 000000000000..153760132982 --- /dev/null +++ b/app/Console/Commands/stubs/command.stub @@ -0,0 +1,68 @@ + '$LOWER_NAME$', + 'datatable' => new $STUDLY_NAME$Datatable(), + 'title' => trans('texts.$LOWER_NAME$'), + ]); + } + + /** + * Show the form for creating a new resource. + * @return Response + */ + public function create() + { + return view('$LOWER_NAME$::create'); + } + + /** + * Store a newly created resource in storage. + * @param Request $request + * @return Response + */ + public function store(Request $request) + { + } + + /** + * Show the form for editing the specified resource. + * @return Response + */ + public function edit() + { + return view('$LOWER_NAME$::edit'); + } + + /** + * Update the specified resource in storage. + * @param Request $request + * @return Response + */ + public function update(Request $request) + { + } + + /** + * Remove the specified resource from storage. + * @return Response + */ + public function destroy() + { + } +} diff --git a/app/Console/Commands/stubs/datatable.stub b/app/Console/Commands/stubs/datatable.stub new file mode 100644 index 000000000000..77cf97357f18 --- /dev/null +++ b/app/Console/Commands/stubs/datatable.stub @@ -0,0 +1,42 @@ +created_at)); + } + ], + ]; + } + + public function actions() + { + return [ + [ + trans('texts.edit_$LOWER_NAME$'), + function ($model) { + return URL::to("$LOWER_NAME$/{$model->public_id}/edit"); + }, + function ($model) { + return Auth::user()->can('editByOwner', ['$LOWER_NAME$', $model->user_id]); + } + ], + ]; + } + +} diff --git a/app/Console/Commands/stubs/event.stub b/app/Console/Commands/stubs/event.stub new file mode 100755 index 000000000000..ad1cb696699c --- /dev/null +++ b/app/Console/Commands/stubs/event.stub @@ -0,0 +1,30 @@ +view('view.name'); + } +} diff --git a/app/Console/Commands/stubs/middleware.stub b/app/Console/Commands/stubs/middleware.stub new file mode 100755 index 000000000000..954583ed4cf5 --- /dev/null +++ b/app/Console/Commands/stubs/middleware.stub @@ -0,0 +1,21 @@ +increments('id'); + $table->unsignedInteger('user_id')->index(); + $table->unsignedInteger('account_id')->index(); + $table->unsignedInteger('client_id')->index()->nullable(); + +$FIELDS$ + $table->timestamps(); + $table->boolean('is_deleted')->default(false); + + $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); + + $table->unsignedInteger('public_id')->index(); + $table->unique( ['account_id', 'public_id'] ); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('$TABLE$'); + } +} diff --git a/app/Console/Commands/stubs/migration/delete.stub b/app/Console/Commands/stubs/migration/delete.stub new file mode 100755 index 000000000000..c145a2f5466b --- /dev/null +++ b/app/Console/Commands/stubs/migration/delete.stub @@ -0,0 +1,31 @@ +increments('id'); +$FIELDS$ + $table->timestamps(); + }); + } +} diff --git a/app/Console/Commands/stubs/migration/plain.stub b/app/Console/Commands/stubs/migration/plain.stub new file mode 100755 index 000000000000..73565c28e5d9 --- /dev/null +++ b/app/Console/Commands/stubs/migration/plain.stub @@ -0,0 +1,27 @@ +line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/app/Console/Commands/stubs/provider.stub b/app/Console/Commands/stubs/provider.stub new file mode 100755 index 000000000000..4fd17be8effd --- /dev/null +++ b/app/Console/Commands/stubs/provider.stub @@ -0,0 +1,35 @@ + 'auth', 'prefix' => '$LOWER_NAME$', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function() +{ + Route::get('/', '$STUDLY_NAME$Controller@index'); +}); diff --git a/app/Console/Commands/stubs/scaffold/config.stub b/app/Console/Commands/stubs/scaffold/config.stub new file mode 100755 index 000000000000..74c3001c9c1e --- /dev/null +++ b/app/Console/Commands/stubs/scaffold/config.stub @@ -0,0 +1,5 @@ + '$STUDLY_NAME$' +]; diff --git a/app/Console/Commands/stubs/scaffold/provider.stub b/app/Console/Commands/stubs/scaffold/provider.stub new file mode 100755 index 000000000000..8937f5caa8e2 --- /dev/null +++ b/app/Console/Commands/stubs/scaffold/provider.stub @@ -0,0 +1,98 @@ +registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } + + /** + * Register config. + * + * @return void + */ + protected function registerConfig() + { + $this->publishes([ + __DIR__.'/../$PATH_CONFIG$/config.php' => config_path('$LOWER_NAME$.php'), + ]); + $this->mergeConfigFrom( + __DIR__.'/../$PATH_CONFIG$/config.php', '$LOWER_NAME$' + ); + } + + /** + * Register views. + * + * @return void + */ + public function registerViews() + { + $viewPath = base_path('resources/views/modules/$LOWER_NAME$'); + + $sourcePath = __DIR__.'/../$PATH_VIEWS$'; + + $this->publishes([ + $sourcePath => $viewPath + ]); + + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/$LOWER_NAME$'; + }, \Config::get('view.paths')), [$sourcePath]), '$LOWER_NAME$'); + } + + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $langPath = base_path('resources/lang/modules/$LOWER_NAME$'); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, '$LOWER_NAME$'); + } else { + $this->loadTranslationsFrom(__DIR__ .'/../$PATH_LANG$', '$LOWER_NAME$'); + } + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } +} diff --git a/app/Console/Commands/stubs/seeder.stub b/app/Console/Commands/stubs/seeder.stub new file mode 100755 index 000000000000..dd4349080a87 --- /dev/null +++ b/app/Console/Commands/stubs/seeder.stub @@ -0,0 +1,21 @@ +call("OthersTableSeeder"); + } +} diff --git a/app/Console/Commands/stubs/start.stub b/app/Console/Commands/stubs/start.stub new file mode 100755 index 000000000000..7be329cbe465 --- /dev/null +++ b/app/Console/Commands/stubs/start.stub @@ -0,0 +1,15 @@ +Hello World + +
+ This view is loaded from module: {!! config('$LOWER_NAME$.name') !!} +
+@stop diff --git a/app/Console/Commands/stubs/views/master.stub b/app/Console/Commands/stubs/views/master.stub new file mode 100755 index 000000000000..14fd322d37b6 --- /dev/null +++ b/app/Console/Commands/stubs/views/master.stub @@ -0,0 +1,12 @@ + + + + + + +