commit c9041b2db2c3581c4c445efd82e1242b269d3d29 Author: daeng.deni@dharma.or.id Date: Sat Jun 10 19:58:32 2023 +0700 Initial Module Product - Add Unit - Add Category diff --git a/Config/.gitkeep b/Config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Config/config.php b/Config/config.php new file mode 100644 index 0000000..c46bd06 --- /dev/null +++ b/Config/config.php @@ -0,0 +1,5 @@ + 'Product' +]; diff --git a/Console/.gitkeep b/Console/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/DataTables/CategoryDataTable.php b/DataTables/CategoryDataTable.php new file mode 100644 index 0000000..fe3e520 --- /dev/null +++ b/DataTables/CategoryDataTable.php @@ -0,0 +1,103 @@ +eloquent($query) + ->filter(function ($query) { + $search = request()->get('search'); + if ($search['value'] !== "") { + $query->where('name', 'like', "%" . $search['value'] . "%"); + } + }) + ->addIndexColumn() + ->addColumn('status', function ($model) { + return view('product::master._status', compact('model')); + }) + ->addColumn('action', function ($model) { + return view('product::master._action', compact('model')); + }) + ->rawColumns(['status','action']); + } + + /** + * Get query source of dataTable. + * + * @param \Modules\Product\Entities\Category $model + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function query(Category $model) + { + return $model->newQuery(); + } + + /** + * Optional method if you want to use html builder. + * + * @return \Yajra\DataTables\Html\Builder + */ + public function html() + { + return $this->builder() + ->setTableId('product-category-table') + ->columns($this->getColumns()) + ->minifiedAjax() + ->orderBy(1, 'asc') + ->stateSave(false) + ->responsive() + ->autoWidth(false) + ->parameters([ + 'scrollX' => false, + 'drawCallback' => 'function() { KTMenu.createInstances(); }', + ]) + ->addTableClass('align-middle table-row-dashed fs-6 gy-5'); + } + + /** + * Get columns. + * + * @return array + */ + protected function getColumns() + { + return [ + Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false), + Column::make('name')->title(__('Name')), + Column::computed('status')->title(__('Status'))->width(50)->addClass('text-center')->exportable(false), + Column::computed('action') + ->exportable(false) + ->printable(false) + ->width(100) + ->addClass('text-center') + ->responsivePriority(-1), + ]; + } + + /** + * Get filename for export. + * + * @return string + */ + protected function filename() + : string + { + return 'Category_' . date('YmdHis'); + } + } diff --git a/DataTables/UnitDataTable.php b/DataTables/UnitDataTable.php new file mode 100644 index 0000000..7815e6e --- /dev/null +++ b/DataTables/UnitDataTable.php @@ -0,0 +1,103 @@ +eloquent($query) + ->filter(function ($query) { + $search = request()->get('search'); + if ($search['value'] !== "") { + $query->where('name', 'like', "%" . $search['value'] . "%"); + } + }) + ->addIndexColumn() + ->addColumn('status', function ($model) { + return view('product::master._status', compact('model')); + }) + ->addColumn('action', function ($model) { + return view('product::master._action', compact('model')); + }) + ->rawColumns(['status', 'action']); + } + + /** + * Get query source of dataTable. + * + * @param \Modules\Product\Entities\Unit $model + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function query(Unit $model) + { + return $model->newQuery(); + } + + /** + * Optional method if you want to use html builder. + * + * @return \Yajra\DataTables\Html\Builder + */ + public function html() + { + return $this->builder() + ->setTableId('product-unit-table') + ->columns($this->getColumns()) + ->minifiedAjax() + ->orderBy(1, 'asc') + ->stateSave(false) + ->responsive() + ->autoWidth(false) + ->parameters([ + 'scrollX' => false, + 'drawCallback' => 'function() { KTMenu.createInstances(); }', + ]) + ->addTableClass('align-middle table-row-dashed fs-6 gy-5'); + } + + /** + * Get columns. + * + * @return array + */ + protected function getColumns() + { + return [ + Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false), + Column::make('name')->title(__('Name')), + Column::computed('status')->title(__('Status'))->width(50)->addClass('text-center')->exportable(false), + Column::computed('action') + ->exportable(false) + ->printable(false) + ->width(100) + ->addClass('text-center') + ->responsivePriority(-1), + ]; + } + + /** + * Get filename for export. + * + * @return string + */ + protected function filename() + : string + { + return 'Unit_' . date('YmdHis'); + } + } diff --git a/Database/Migrations/.gitkeep b/Database/Migrations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Database/Migrations/2023_06_10_122132_create_units_table.php b/Database/Migrations/2023_06_10_122132_create_units_table.php new file mode 100644 index 0000000..57f87db --- /dev/null +++ b/Database/Migrations/2023_06_10_122132_create_units_table.php @@ -0,0 +1,38 @@ +id(); + $table->string("name"); + $table->string("status")->default(1); + $table->timestamps(); + $table->softDeletes(); + + $table->foreignId("created_by")->nullable()->constrained("users"); + $table->foreignId("updated_by")->nullable()->constrained("users"); + $table->foreignId("deleted_by")->nullable()->constrained("users"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('units'); + } +}; diff --git a/Database/Migrations/2023_06_10_122142_create_categories_table.php b/Database/Migrations/2023_06_10_122142_create_categories_table.php new file mode 100644 index 0000000..eeed9f0 --- /dev/null +++ b/Database/Migrations/2023_06_10_122142_create_categories_table.php @@ -0,0 +1,38 @@ +id(); + $table->string("name"); + $table->string("status")->default(1); + $table->timestamps(); + $table->softDeletes(); + + $table->foreignId("created_by")->nullable()->constrained("users"); + $table->foreignId("updated_by")->nullable()->constrained("users"); + $table->foreignId("deleted_by")->nullable()->constrained("users"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('categories'); + } +}; diff --git a/Database/Seeders/.gitkeep b/Database/Seeders/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Database/Seeders/ProductDatabaseSeeder.php b/Database/Seeders/ProductDatabaseSeeder.php new file mode 100644 index 0000000..225a716 --- /dev/null +++ b/Database/Seeders/ProductDatabaseSeeder.php @@ -0,0 +1,67 @@ +forgetCachedPermissions(); + + $data = $this->data(); + foreach ($data as $value) { + $permission = Permission::updateOrCreate([ + 'name' => $value['name'], + 'guard_name' => 'web' + ], [ + 'permission_group_id' => $value['group'], + ]); + + $role = Role::find(1); + $role->givePermissionTo($permission); + } + } + + public function data() + { + $data = []; + // list of model permission + $model = ['product']; + + foreach ($model as $value) { + $permissionGroup = PermissionGroup::updateOrCreate([ + 'name' => $value + ]); + + foreach ($this->crudActions($value) as $action) { + $data[] = ['name' => $action, 'group' => $permissionGroup->id]; + } + } + + return $data; + } + + public function crudActions($name) + { + $actions = []; + // list of permission actions + $crud = ['create', 'read', 'update', 'delete']; + + foreach ($crud as $value) { + $actions[] = $name . '.' . $value; + } + + return $actions; + } + } diff --git a/Database/factories/.gitkeep b/Database/factories/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Entities/.gitkeep b/Entities/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Entities/BaseModel.php b/Entities/BaseModel.php new file mode 100644 index 0000000..8f982ae --- /dev/null +++ b/Entities/BaseModel.php @@ -0,0 +1,34 @@ +connection = $module->database; + } + + public function getActivitylogOptions() + : LogOptions + { + return LogOptions::defaults()->logAll() + ->useLogName('Buyer : '); + } + + } diff --git a/Entities/Category.php b/Entities/Category.php new file mode 100644 index 0000000..a0e79df --- /dev/null +++ b/Entities/Category.php @@ -0,0 +1,14 @@ +middleware(function ($request, $next) { + $this->user = Auth::guard('web')->user(); + return $next($request); + }); + + $module = file_get_contents(dirname(__FILE__, 3) . '/module.json'); + $this->module = json_decode($module); + } + + /** + * Display a listing of the resource. + * + * @return Renderable + */ + public function index(CategoryDataTable $dataTable) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) { + abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !'); + } + + return $dataTable->render($this->module->alias . '::master.index'); + } + + /** + * Store a newly created resource in storage. + * + * @param Request $request + * + * @return Renderable + */ + public function store(StoreCategoryRequest $request) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.create')) { + abort(403, 'Sorry !! You are Unauthorized to create any ' . $this->module->alias . ' !'); + } + + //Validate the request + $validated = $request->validated(); + + // Store the Category... + if ($validated) { + try { + $this->model::create($validated); + echo json_encode(['status' => 'success', 'message' => $this->module->name . ' category created successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' category created failed.']); + } + return; + } + + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' category created failed.']); + } + + /** + * Show the form for creating a new resource. + * + * @return Renderable + */ + public function create() + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.create')) { + abort(403, 'Sorry !! You are Unauthorized to create any ' . $this->module->alias . ' !'); + } + + abort(404); + } + + /** + * Show the specified resource. + * + * @param int $id + * + * @return Renderable + */ + public function show($id) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) { + abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !'); + } + + abort(404); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * + * @return Renderable + */ + public function edit($id) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.update')) { + abort(403, 'Sorry !! You are Unauthorized to update any ' . $this->module->alias . ' !'); + } + + $data = $this->model::find($id); + echo json_encode($data); + } + + /** + * Update the specified resource in storage. + * + * @param Request $request + * @param int $id + * + * @return Renderable + */ + public function update(UpdateCategoryRequest $request, Category $category) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.update')) { + abort(403, 'Sorry !! You are Unauthorized to update any ' . $this->module->alias . ' !'); + } + + //Validate the request + $validated = $request->validated(); + + // Update the Category... + if ($validated) { + try { + $category->update($validated); + echo json_encode(['status' => 'success', 'message' => $this->module->name . ' category updated successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' category updated failed.']); + } + return; + } + + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' category updated failed.']); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * + * @return Renderable + */ + public function destroy(Category $category) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.delete')) { + abort(403, 'Sorry !! You are Unauthorized to delete any ' . $this->module->alias . ' !'); + } + + try { + $category->delete(); + echo json_encode(['status' => 'success', 'message' => $this->module->name . ' category deleted successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' category deleted failed.']); + } + } + } diff --git a/Http/Controllers/UnitController.php b/Http/Controllers/UnitController.php new file mode 100644 index 0000000..ca230eb --- /dev/null +++ b/Http/Controllers/UnitController.php @@ -0,0 +1,174 @@ +middleware(function ($request, $next) { + $this->user = Auth::guard('web')->user(); + return $next($request); + }); + + $module = file_get_contents(dirname(__FILE__, 3) . '/module.json'); + $this->module = json_decode($module); + } + + /** + * Display a listing of the resource. + * + * @return Renderable + */ + public function index(UnitDataTable $dataTable) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) { + abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !'); + } + + return $dataTable->render($this->module->alias . '::master.index'); + } + + /** + * Store a newly created resource in storage. + * + * @param Request $request + * + * @return Renderable + */ + public function store(StoreUnitRequest $request) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.create')) { + abort(403, 'Sorry !! You are Unauthorized to create any ' . $this->module->alias . ' !'); + } + + //Validate the request + $validated = $request->validated(); + + // Store the Unit... + if ($validated) { + try { + $this->model::create($validated); + echo json_encode(['status' => 'success', 'message' => $this->module->name . ' unit created successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' unit created failed.']); + } + return; + } + + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' unit created failed.']); + } + + /** + * Show the form for creating a new resource. + * + * @return Renderable + */ + public function create() + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.create')) { + abort(403, 'Sorry !! You are Unauthorized to create any ' . $this->module->alias . ' !'); + } + + abort(404); + } + + /** + * Show the specified resource. + * + * @param int $id + * + * @return Renderable + */ + public function show($id) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.read')) { + abort(403, 'Sorry !! You are Unauthorized to view any ' . $this->module->alias . ' !'); + } + + abort(404); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * + * @return Renderable + */ + public function edit($id) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.update')) { + abort(403, 'Sorry !! You are Unauthorized to update any ' . $this->module->alias . ' !'); + } + + $data = $this->model::find($id); + echo json_encode($data); + } + + /** + * Update the specified resource in storage. + * + * @param Request $request + * @param int $id + * + * @return Renderable + */ + public function update(UpdateUnitRequest $request, Unit $unit) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.update')) { + abort(403, 'Sorry !! You are Unauthorized to update any ' . $this->module->alias . ' !'); + } + + //Validate the request + $validated = $request->validated(); + + // Update the Unit... + if ($validated) { + try { + $unit->update($validated); + echo json_encode(['status' => 'success', 'message' => $this->module->name . ' unit updated successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' unit updated failed.']); + } + return; + } + + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' unit updated failed.']); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * + * @return Renderable + */ + public function destroy(Unit $unit) + { + if (is_null($this->user) || !$this->user->can($this->module->alias . '.delete')) { + abort(403, 'Sorry !! You are Unauthorized to delete any ' . $this->module->alias . ' !'); + } + + try { + $unit->delete(); + echo json_encode(['status' => 'success', 'message' => $this->module->name . ' unit deleted successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => $this->module->name . ' unit deleted failed.']); + } + } + } diff --git a/Http/Middleware/.gitkeep b/Http/Middleware/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Http/Requests/.gitkeep b/Http/Requests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Http/Requests/Category/StoreCategoryRequest.php b/Http/Requests/Category/StoreCategoryRequest.php new file mode 100644 index 0000000..aa2fa8c --- /dev/null +++ b/Http/Requests/Category/StoreCategoryRequest.php @@ -0,0 +1,67 @@ + + */ + public function rules() + : array + { + return [ + 'name' => 'required|string|max:50|unique:categories,name', + 'status' => 'nullable|integer|max:1', + ]; + } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator) + : void + { + $validator->after(function (Validator $validator) { + if ($validator->errors()->any()) { + $errors = json_decode($validator->errors()->toJson(), true); + + foreach ($errors as $key => $value) { + flash($value[0]); + } + return redirect()->route('master.category.index')->with('error', 'Category created failed.'); + } + + }); + } + + protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator) + : JsonResponse + { + $errors = (new ValidationException($validator))->errors(); + + throw new HttpResponseException(response()->json([ + 'success' => false, + 'errors' => $errors, + 'messages' => 'Category created failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + + } diff --git a/Http/Requests/Category/UpdateCategoryRequest.php b/Http/Requests/Category/UpdateCategoryRequest.php new file mode 100644 index 0000000..76807bc --- /dev/null +++ b/Http/Requests/Category/UpdateCategoryRequest.php @@ -0,0 +1,67 @@ + + */ + public function rules() + : array + { + return [ + 'name' => 'required|string|max:50|unique:categories,name,'.$this->category->id, + 'status' => 'nullable|integer|max:1', + ]; + } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator) + : void + { + $validator->after(function (Validator $validator) { + if ($validator->errors()->any()) { + $errors = json_decode($validator->errors()->toJson(), true); + + foreach ($errors as $key => $value) { + flash($value[0]); + } + return redirect()->route('master.category.index')->with('error', 'Category updated failed.'); + } + + }); + } + + protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator) + : JsonResponse + { + $errors = (new ValidationException($validator))->errors(); + + throw new HttpResponseException(response()->json([ + 'success' => false, + 'errors' => $errors, + 'messages' => 'Category updated failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + + } diff --git a/Http/Requests/ProductRequest.php b/Http/Requests/ProductRequest.php new file mode 100644 index 0000000..8b6db65 --- /dev/null +++ b/Http/Requests/ProductRequest.php @@ -0,0 +1,19 @@ +status == "on") { + $status = 1; + } + $this->merge([ + 'status' => $status + ]); + } + } diff --git a/Http/Requests/Unit/StoreUnitRequest.php b/Http/Requests/Unit/StoreUnitRequest.php new file mode 100644 index 0000000..4cca898 --- /dev/null +++ b/Http/Requests/Unit/StoreUnitRequest.php @@ -0,0 +1,67 @@ + + */ + public function rules() + : array + { + return [ + 'name' => 'required|string|max:50|unique:units,name', + 'status' => 'nullable|integer|max:1', + ]; + } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator) + : void + { + $validator->after(function (Validator $validator) { + if ($validator->errors()->any()) { + $errors = json_decode($validator->errors()->toJson(), true); + + foreach ($errors as $key => $value) { + flash($value[0]); + } + return redirect()->route('master.unit.index')->with('error', 'Unit created failed.'); + } + + }); + } + + protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator) + : JsonResponse + { + $errors = (new ValidationException($validator))->errors(); + + throw new HttpResponseException(response()->json([ + 'success' => false, + 'errors' => $errors, + 'messages' => 'Unit created failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + + } diff --git a/Http/Requests/Unit/UpdateUnitRequest.php b/Http/Requests/Unit/UpdateUnitRequest.php new file mode 100644 index 0000000..1b648f0 --- /dev/null +++ b/Http/Requests/Unit/UpdateUnitRequest.php @@ -0,0 +1,67 @@ + + */ + public function rules() + : array + { + return [ + 'name' => 'required|string|max:50|unique:units,name,' . $this->unit->id, + 'status' => 'nullable|integer|max:1', + ]; + } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator) + : void + { + $validator->after(function (Validator $validator) { + if ($validator->errors()->any()) { + $errors = json_decode($validator->errors()->toJson(), true); + + foreach ($errors as $key => $value) { + flash($value[0]); + } + return redirect()->route('master.unit.index')->with('error', 'Unit updated failed.'); + } + + }); + } + + protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator) + : JsonResponse + { + $errors = (new ValidationException($validator))->errors(); + + throw new HttpResponseException(response()->json([ + 'success' => false, + 'errors' => $errors, + 'messages' => 'Unit updated failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + + } diff --git a/Providers/.gitkeep b/Providers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Providers/ProductServiceProvider.php b/Providers/ProductServiceProvider.php new file mode 100644 index 0000000..3862a73 --- /dev/null +++ b/Providers/ProductServiceProvider.php @@ -0,0 +1,114 @@ +registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register config. + * + * @return void + */ + protected function registerConfig() + { + $this->publishes([ + module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), + ], 'config'); + $this->mergeConfigFrom( + module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower + ); + } + + /** + * Register views. + * + * @return void + */ + public function registerViews() + { + $viewPath = resource_path('views/modules/' . $this->moduleNameLower); + + $sourcePath = module_path($this->moduleName, 'Resources/views'); + + $this->publishes([ + $sourcePath => $viewPath + ], ['views', $this->moduleNameLower . '-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + } + + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $langPath = resource_path('lang/modules/' . $this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); + } + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } + + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (\Config::get('view.paths') as $path) { + if (is_dir($path . '/modules/' . $this->moduleNameLower)) { + $paths[] = $path . '/modules/' . $this->moduleNameLower; + } + } + return $paths; + } +} diff --git a/Providers/RouteServiceProvider.php b/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..9b9416f --- /dev/null +++ b/Providers/RouteServiceProvider.php @@ -0,0 +1,69 @@ +mapApiRoutes(); + + $this->mapWebRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + * + * @return void + */ + protected function mapWebRoutes() + { + Route::middleware('web') + ->namespace($this->moduleNamespace) + ->group(module_path('Product', '/Routes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + * + * @return void + */ + protected function mapApiRoutes() + { + Route::prefix('api') + ->middleware('api') + ->namespace($this->moduleNamespace) + ->group(module_path('Product', '/Routes/api.php')); + } +} diff --git a/Resources/assets/.gitkeep b/Resources/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Resources/assets/js/app.js b/Resources/assets/js/app.js new file mode 100644 index 0000000..e69de29 diff --git a/Resources/assets/sass/app.scss b/Resources/assets/sass/app.scss new file mode 100644 index 0000000..e69de29 diff --git a/Resources/lang/.gitkeep b/Resources/lang/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Resources/views/.gitkeep b/Resources/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Resources/views/master/_action.blade.php b/Resources/views/master/_action.blade.php new file mode 100644 index 0000000..a32eac2 --- /dev/null +++ b/Resources/views/master/_action.blade.php @@ -0,0 +1,13 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp +
+ + {!! getIcon("pencil", "fs-1 text-info","duotune") !!} + + + {!! Form::open(['method' => 'DELETE','route' => [$route[0].'.'.$route[1].'.destroy', $model->id],'class'=>'']) !!} + {{ Form::button(getIcon("trash", "fs-1 text-danger","duotune"), ['type' => 'submit', 'class' => 'delete btn btn-icon btn-bg-light btn-active-light-danger btn-sm'] ) }} + {!! Form::close() !!} +
diff --git a/Resources/views/master/_form.blade.php b/Resources/views/master/_form.blade.php new file mode 100644 index 0000000..94647e5 --- /dev/null +++ b/Resources/views/master/_form.blade.php @@ -0,0 +1,64 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp + + + + diff --git a/Resources/views/master/_status.blade.php b/Resources/views/master/_status.blade.php new file mode 100644 index 0000000..1b62790 --- /dev/null +++ b/Resources/views/master/_status.blade.php @@ -0,0 +1,10 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp + +{!! Form::open(['method' => 'PUT','route' => [$route[0].'.'.$route[1].'.update', $model->id],'class'=>'']) !!} +
+ status==1 ? 'checked' : '' }} type="checkbox" name="status" id="status"/> + +
+{!! Form::close() !!} diff --git a/Resources/views/master/_table.blade.php b/Resources/views/master/_table.blade.php new file mode 100644 index 0000000..75ee5cc --- /dev/null +++ b/Resources/views/master/_table.blade.php @@ -0,0 +1,132 @@ + +{{ $dataTable->table() }} + + +{{-- Inject Scripts --}} +@section('scripts') + {{ $dataTable->scripts() }} +@endsection + +@push('customscript') + @php + $route = explode('.', Route::currentRouteName()); + @endphp + + +@endpush + +@section('styles') + +@endsection diff --git a/Resources/views/master/index.blade.php b/Resources/views/master/index.blade.php new file mode 100644 index 0000000..d5fd3d5 --- /dev/null +++ b/Resources/views/master/index.blade.php @@ -0,0 +1,135 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp + + + +
+ +
+
+
+ + + + + + + + + +
+ + +
+ + +
+ +
+ + + + + + + +
+ + +
+
+
+ @include($route[0].'::master._table') + @include($route[0].'::master._form') +
+ +
+ + @push('customscript') + + @endpush +
diff --git a/Resources/views/partials/menu/_app.blade.php b/Resources/views/partials/menu/_app.blade.php new file mode 100644 index 0000000..baa96b8 --- /dev/null +++ b/Resources/views/partials/menu/_app.blade.php @@ -0,0 +1,42 @@ +@canany(['product.read','product.create','product.update','product.delete']) + + + +@endcanany diff --git a/Routes/.gitkeep b/Routes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Routes/api.php b/Routes/api.php new file mode 100644 index 0000000..8e94dbe --- /dev/null +++ b/Routes/api.php @@ -0,0 +1,18 @@ +get('/product', function (Request $request) { + return $request->user(); +}); \ No newline at end of file diff --git a/Routes/web.php b/Routes/web.php new file mode 100644 index 0000000..b4f0861 --- /dev/null +++ b/Routes/web.php @@ -0,0 +1,22 @@ +group(function () { + Route::prefix('product')->name('product.')->group(function () { + Route::resource('unit', UnitController::class); + Route::resource('category', CategoryController::class); + }); + }); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..893900e --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "putrakuningan/product-module", + "type": "laravel-module", + "description": "", + "authors": [ + { + "name": "Daeng Deni Mardaeni", + "email": "ddeni05@gmail.com" + } + ], + "extra": { + "laravel": { + "providers": [], + "aliases": { + + } + } + }, + "autoload": { + "psr-4": { + "Modules\\Product\\": "" + } + } +} diff --git a/module.json b/module.json new file mode 100644 index 0000000..a7448b3 --- /dev/null +++ b/module.json @@ -0,0 +1,13 @@ +{ + "name": "Product", + "alias": "product", + "description": "", + "database": "", + "domain": "", + "keywords": [], + "priority": 0, + "providers": [ + "Modules\\Product\\Providers\\ProductServiceProvider" + ], + "files": [] +}