Initial Module Product
- Add Unit - Add Category
This commit is contained in:
commit
c9041b2db2
0
Config/.gitkeep
Normal file
0
Config/.gitkeep
Normal file
5
Config/config.php
Normal file
5
Config/config.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => 'Product'
|
||||||
|
];
|
0
Console/.gitkeep
Normal file
0
Console/.gitkeep
Normal file
103
DataTables/CategoryDataTable.php
Normal file
103
DataTables/CategoryDataTable.php
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\DataTables;
|
||||||
|
|
||||||
|
use Modules\Product\Entities\Category;
|
||||||
|
use Yajra\DataTables\Html\Column;
|
||||||
|
use Yajra\DataTables\Services\DataTable;
|
||||||
|
|
||||||
|
class CategoryDataTable extends DataTable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Build DataTable class.
|
||||||
|
*
|
||||||
|
* @param mixed $query Results from query() method.
|
||||||
|
*
|
||||||
|
* @return \Yajra\DataTables\DataTableAbstract
|
||||||
|
*/
|
||||||
|
public function dataTable($query)
|
||||||
|
{
|
||||||
|
|
||||||
|
return datatables()
|
||||||
|
->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');
|
||||||
|
}
|
||||||
|
}
|
103
DataTables/UnitDataTable.php
Normal file
103
DataTables/UnitDataTable.php
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\DataTables;
|
||||||
|
|
||||||
|
use Modules\Product\Entities\Unit;
|
||||||
|
use Yajra\DataTables\Html\Column;
|
||||||
|
use Yajra\DataTables\Services\DataTable;
|
||||||
|
|
||||||
|
class UnitDataTable extends DataTable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Build DataTable class.
|
||||||
|
*
|
||||||
|
* @param mixed $query Results from query() method.
|
||||||
|
*
|
||||||
|
* @return \Yajra\DataTables\DataTableAbstract
|
||||||
|
*/
|
||||||
|
public function dataTable($query)
|
||||||
|
{
|
||||||
|
|
||||||
|
return datatables()
|
||||||
|
->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');
|
||||||
|
}
|
||||||
|
}
|
0
Database/Migrations/.gitkeep
Normal file
0
Database/Migrations/.gitkeep
Normal file
38
Database/Migrations/2023_06_10_122132_create_units_table.php
Normal file
38
Database/Migrations/2023_06_10_122132_create_units_table.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('units', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('categories', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
};
|
0
Database/Seeders/.gitkeep
Normal file
0
Database/Seeders/.gitkeep
Normal file
67
Database/Seeders/ProductDatabaseSeeder.php
Normal file
67
Database/Seeders/ProductDatabaseSeeder.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Modules\Usermanager\Entities\PermissionGroup;
|
||||||
|
use Spatie\Permission\Models\Permission;
|
||||||
|
use Spatie\Permission\Models\Role;
|
||||||
|
use Spatie\Permission\PermissionRegistrar;
|
||||||
|
|
||||||
|
class ProductDatabaseSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
app()[PermissionRegistrar::class]->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;
|
||||||
|
}
|
||||||
|
}
|
0
Database/factories/.gitkeep
Normal file
0
Database/factories/.gitkeep
Normal file
0
Entities/.gitkeep
Normal file
0
Entities/.gitkeep
Normal file
34
Entities/BaseModel.php
Normal file
34
Entities/BaseModel.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Spatie\Activitylog\LogOptions;
|
||||||
|
use Spatie\Activitylog\Traits\LogsActivity;
|
||||||
|
use Wildside\Userstamps\Userstamps;
|
||||||
|
|
||||||
|
class BaseModel extends Model
|
||||||
|
{
|
||||||
|
use LogsActivity, HasFactory, SoftDeletes, Userstamps;
|
||||||
|
|
||||||
|
protected $connection;
|
||||||
|
|
||||||
|
public function __construct(array $attributes = [])
|
||||||
|
{
|
||||||
|
parent::__construct($attributes);
|
||||||
|
$module = file_get_contents(dirname(__FILE__, 2) . '/module.json');
|
||||||
|
$module = json_decode($module);
|
||||||
|
|
||||||
|
$this->connection = $module->database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActivitylogOptions()
|
||||||
|
: LogOptions
|
||||||
|
{
|
||||||
|
return LogOptions::defaults()->logAll()
|
||||||
|
->useLogName('Buyer : ');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
Entities/Category.php
Normal file
14
Entities/Category.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Entities;
|
||||||
|
|
||||||
|
class Category extends BaseModel
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'status',
|
||||||
|
'created_by',
|
||||||
|
'updated_by',
|
||||||
|
'deleted_by',
|
||||||
|
];
|
||||||
|
}
|
14
Entities/Unit.php
Normal file
14
Entities/Unit.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Entities;
|
||||||
|
|
||||||
|
class Unit extends BaseModel
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'status',
|
||||||
|
'created_by',
|
||||||
|
'updated_by',
|
||||||
|
'deleted_by',
|
||||||
|
];
|
||||||
|
}
|
0
Http/Controllers/.gitkeep
Normal file
0
Http/Controllers/.gitkeep
Normal file
174
Http/Controllers/CategoryController.php
Normal file
174
Http/Controllers/CategoryController.php
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Http\Controllers;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Contracts\Support\Renderable;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Controller;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Modules\Product\DataTables\CategoryDataTable;
|
||||||
|
use Modules\Product\Entities\Category;
|
||||||
|
use Modules\Product\Http\Requests\Category\StoreCategoryRequest;
|
||||||
|
use Modules\Product\Http\Requests\Category\UpdateCategoryRequest;
|
||||||
|
|
||||||
|
class CategoryController extends Controller
|
||||||
|
{
|
||||||
|
protected $user;
|
||||||
|
protected $model = Category::class;
|
||||||
|
protected $module;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->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.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
174
Http/Controllers/UnitController.php
Normal file
174
Http/Controllers/UnitController.php
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Http\Controllers;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Contracts\Support\Renderable;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Controller;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Modules\Product\DataTables\UnitDataTable;
|
||||||
|
use Modules\Product\Entities\Unit;
|
||||||
|
use Modules\Product\Http\Requests\Unit\StoreUnitRequest;
|
||||||
|
use Modules\Product\Http\Requests\Unit\UpdateUnitRequest;
|
||||||
|
|
||||||
|
class UnitController extends Controller
|
||||||
|
{
|
||||||
|
protected $user;
|
||||||
|
protected $model = Unit::class;
|
||||||
|
protected $module;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->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.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
0
Http/Middleware/.gitkeep
Normal file
0
Http/Middleware/.gitkeep
Normal file
0
Http/Requests/.gitkeep
Normal file
0
Http/Requests/.gitkeep
Normal file
67
Http/Requests/Category/StoreCategoryRequest.php
Normal file
67
Http/Requests/Category/StoreCategoryRequest.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Http\Requests\Category;
|
||||||
|
|
||||||
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Illuminate\Validation\Validator;
|
||||||
|
use Modules\Product\Http\Requests\ProductRequest;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
|
class StoreCategoryRequest extends ProductRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
: bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
|
||||||
|
*/
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
67
Http/Requests/Category/UpdateCategoryRequest.php
Normal file
67
Http/Requests/Category/UpdateCategoryRequest.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Http\Requests\Category;
|
||||||
|
|
||||||
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Illuminate\Validation\Validator;
|
||||||
|
use Modules\Product\Http\Requests\ProductRequest;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
|
class UpdateCategoryRequest extends ProductRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
: bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
|
||||||
|
*/
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
Http/Requests/ProductRequest.php
Normal file
19
Http/Requests/ProductRequest.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ProductRequest extends FormRequest
|
||||||
|
{
|
||||||
|
protected function prepareForValidation()
|
||||||
|
{
|
||||||
|
$status = 0;
|
||||||
|
if ($this->status == "on") {
|
||||||
|
$status = 1;
|
||||||
|
}
|
||||||
|
$this->merge([
|
||||||
|
'status' => $status
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
67
Http/Requests/Unit/StoreUnitRequest.php
Normal file
67
Http/Requests/Unit/StoreUnitRequest.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Http\Requests\Unit;
|
||||||
|
|
||||||
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Illuminate\Validation\Validator;
|
||||||
|
use Modules\Product\Http\Requests\ProductRequest;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
|
class StoreUnitRequest extends ProductRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
: bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
|
||||||
|
*/
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
67
Http/Requests/Unit/UpdateUnitRequest.php
Normal file
67
Http/Requests/Unit/UpdateUnitRequest.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Http\Requests\Unit;
|
||||||
|
|
||||||
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Illuminate\Validation\Validator;
|
||||||
|
use Modules\Product\Http\Requests\ProductRequest;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
|
class UpdateUnitRequest extends ProductRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
: bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
|
||||||
|
*/
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
0
Providers/.gitkeep
Normal file
0
Providers/.gitkeep
Normal file
114
Providers/ProductServiceProvider.php
Normal file
114
Providers/ProductServiceProvider.php
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Illuminate\Database\Eloquent\Factory;
|
||||||
|
|
||||||
|
class ProductServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string $moduleName
|
||||||
|
*/
|
||||||
|
protected $moduleName = 'Product';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string $moduleNameLower
|
||||||
|
*/
|
||||||
|
protected $moduleNameLower = 'product';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boot the application events.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
69
Providers/RouteServiceProvider.php
Normal file
69
Providers/RouteServiceProvider.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Product\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||||
|
|
||||||
|
class RouteServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The module namespace to assume when generating URLs to actions.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $moduleNamespace = 'Modules\Product\Http\Controllers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called before routes are registered.
|
||||||
|
*
|
||||||
|
* Register any model bindings or pattern based filters.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the routes for the application.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function map()
|
||||||
|
{
|
||||||
|
$this->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'));
|
||||||
|
}
|
||||||
|
}
|
0
Resources/assets/.gitkeep
Normal file
0
Resources/assets/.gitkeep
Normal file
0
Resources/assets/js/app.js
Normal file
0
Resources/assets/js/app.js
Normal file
0
Resources/assets/sass/app.scss
Normal file
0
Resources/assets/sass/app.scss
Normal file
0
Resources/lang/.gitkeep
Normal file
0
Resources/lang/.gitkeep
Normal file
0
Resources/views/.gitkeep
Normal file
0
Resources/views/.gitkeep
Normal file
13
Resources/views/master/_action.blade.php
Normal file
13
Resources/views/master/_action.blade.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
@php
|
||||||
|
$route = explode('.', Route::currentRouteName());
|
||||||
|
@endphp
|
||||||
|
<div class="d-flex flex-row flex-center">
|
||||||
|
<a href="{{ route($route[0].'.'.$route[1].'.edit',[$route[1] => $model->id]) }}"
|
||||||
|
class="kt_edit_form btn btn-icon btn-bg-light btn-active-light-primary btn-sm me-1">
|
||||||
|
{!! getIcon("pencil", "fs-1 text-info","duotune") !!}
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{!! 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() !!}
|
||||||
|
</div>
|
64
Resources/views/master/_form.blade.php
Normal file
64
Resources/views/master/_form.blade.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
@php
|
||||||
|
$route = explode('.', Route::currentRouteName());
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<!--begin::Modal - New Target-->
|
||||||
|
<div class="modal fade" id="kt_modal_{{$route[0].'_'.$route[1]}}" tabindex="-1" aria-hidden="true">
|
||||||
|
<!--begin::Modal dialog-->
|
||||||
|
<div class="modal-dialog modal-dialog-centered mw-650px">
|
||||||
|
<!--begin::Modal content-->
|
||||||
|
<div class="modal-content rounded">
|
||||||
|
<!--begin::Modal header-->
|
||||||
|
<div class="modal-header pb-0 border-0 justify-content-end">
|
||||||
|
<!--begin::Close-->
|
||||||
|
<div class="btn btn-sm btn-icon btn-active-color-primary" data-bs-dismiss="modal">{!! getIcon('cross', 'fs-1') !!}</div>
|
||||||
|
<!--end::Close-->
|
||||||
|
</div>
|
||||||
|
<!--begin::Modal header-->
|
||||||
|
<!--begin::Modal body-->
|
||||||
|
<div class="modal-body scroll-y px-10 px-lg-15 pt-0 pb-15">
|
||||||
|
<!--begin:Form-->
|
||||||
|
<form class="form_{{$route[0].'_'.$route[1]}}" method="POST" action="{{ route($route[0].'.'.$route[1].'.store') }}">
|
||||||
|
@csrf
|
||||||
|
<!--begin::Heading-->
|
||||||
|
<div class="mb-13 text-center">
|
||||||
|
<!--begin::Title-->
|
||||||
|
<h1 class="mb-3 text-capitalize" id="title_form">{{ str_replace('-',' ',$route[0].' '.$route[1]) }}</h1>
|
||||||
|
<!--end::Title-->
|
||||||
|
</div>
|
||||||
|
<!--end::Heading-->
|
||||||
|
<!--begin::Input group-->
|
||||||
|
<div class="d-flex flex-column mb-8 fv-row">
|
||||||
|
<!--begin::Label-->
|
||||||
|
<label class="d-flex align-items-center fs-6 fw-semibold mb-2">
|
||||||
|
<span class="required">Name</span>
|
||||||
|
<span class="ms-1" data-bs-toggle="tooltip" title="Specify a target name for future usage and reference"></span>
|
||||||
|
</label>
|
||||||
|
<!--end::Label-->
|
||||||
|
<input type="hidden" id="{{$route[0].'_'.$route[1]}}_id" name="id"/>
|
||||||
|
<input type="text" id="{{$route[0].'_'.$route[1]}}_name" maxlength="50" class="form-control form-control-solid" placeholder="Enter {{ ucfirst($route[1]) }} Name" name="name"/>
|
||||||
|
</div>
|
||||||
|
<!--end::Input group-->
|
||||||
|
<div class="form-check form-switch form-check-custom form-check-solid" style="display: block!important;">
|
||||||
|
<input class="form-check-input h-20px w-30px me-5" type="checkbox" name="status" id="{{$route[0].'_'.$route[1]}}_status"/>
|
||||||
|
<label class="form-check-label" for="{{$route[0].'_'.$route[1]}}_status">
|
||||||
|
Aktif
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--begin::Actions-->
|
||||||
|
<div class="text-center">
|
||||||
|
<button type="reset" data-bs-dismiss="modal" class="btn btn-light me-3">Cancel</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</div>
|
||||||
|
<!--end::Actions-->
|
||||||
|
</form>
|
||||||
|
<!--end:Form-->
|
||||||
|
</div>
|
||||||
|
<!--end::Modal body-->
|
||||||
|
</div>
|
||||||
|
<!--end::Modal content-->
|
||||||
|
</div>
|
||||||
|
<!--end::Modal dialog-->
|
||||||
|
</div>
|
||||||
|
<!--end::Modal - New Target-->
|
10
Resources/views/master/_status.blade.php
Normal file
10
Resources/views/master/_status.blade.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
@php
|
||||||
|
$route = explode('.', Route::currentRouteName());
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
{!! Form::open(['method' => 'PUT','route' => [$route[0].'.'.$route[1].'.update', $model->id],'class'=>'']) !!}
|
||||||
|
<div class="form-check form-switch form-check-custom form-check-solid" style="display: block!important;">
|
||||||
|
<input class="form-check-input h-20px w-30px status" {{ $model->status==1 ? 'checked' : '' }} type="checkbox" name="status" id="status"/>
|
||||||
|
<input type="hidden" value="{{$model->name}}" name="name">
|
||||||
|
</div>
|
||||||
|
{!! Form::close() !!}
|
132
Resources/views/master/_table.blade.php
Normal file
132
Resources/views/master/_table.blade.php
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<!--begin::Table-->
|
||||||
|
{{ $dataTable->table() }}
|
||||||
|
<!--end::Table-->
|
||||||
|
|
||||||
|
{{-- Inject Scripts --}}
|
||||||
|
@section('scripts')
|
||||||
|
{{ $dataTable->scripts() }}
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('customscript')
|
||||||
|
@php
|
||||||
|
$route = explode('.', Route::currentRouteName());
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$("#searchbox").on("keyup search input paste cut", function () {
|
||||||
|
LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].search(this.value).draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
const documentTitle = '{{ ucfirst($route[0].' '.$route[1]) }} Report';
|
||||||
|
var buttons = new $.fn.dataTable.Buttons(LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"], {
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
extend: 'copyHtml5',
|
||||||
|
title: documentTitle
|
||||||
|
},
|
||||||
|
{
|
||||||
|
extend: 'excelHtml5',
|
||||||
|
title: documentTitle
|
||||||
|
},
|
||||||
|
{
|
||||||
|
extend: 'csvHtml5',
|
||||||
|
title: documentTitle
|
||||||
|
},
|
||||||
|
{
|
||||||
|
extend: 'pdfHtml5',
|
||||||
|
title: documentTitle
|
||||||
|
},
|
||||||
|
{
|
||||||
|
extend: 'print',
|
||||||
|
title: documentTitle
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).container().appendTo($('#kt_datatable_example_buttons'));
|
||||||
|
|
||||||
|
// Hook dropdown menu click event to datatable export buttons
|
||||||
|
const exportButtons = document.querySelectorAll('#kt_datatable_example_export_menu [data-kt-export]');
|
||||||
|
exportButtons.forEach(exportButton => {
|
||||||
|
exportButton.addEventListener('click', e => {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log(e.target.getAttribute('data-kt-export'));
|
||||||
|
// Get clicked export value
|
||||||
|
const exportValue = e.target.getAttribute('data-kt-export');
|
||||||
|
const target = document.querySelector('.dt-buttons .buttons-' + exportValue);
|
||||||
|
|
||||||
|
// Trigger click event on hidden datatable export buttons
|
||||||
|
target.click();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('click', '.kt_edit_form', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
$.ajax({
|
||||||
|
url: $(this).attr('href'),
|
||||||
|
type: 'GET',
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (response) {
|
||||||
|
$('#title_form').text('Edit {{ ucfirst(str_replace('-',' ',$route[0].' '.$route[1])) }}');
|
||||||
|
$('#{{$route[0].'_'.$route[1]}}_id').val(response.id);
|
||||||
|
$('#{{$route[0].'_'.$route[1]}}_name').val(response.name);
|
||||||
|
$('#{{$route[0].'_'.$route[1]}}_status').prop('checked', response.status==="1");
|
||||||
|
$('.form_{{$route[0].'_'.$route[1]}}').attr('action', '{{ URL::to('/'.$route[0].'/'.$route[1].'/') }}/' + response.id).append('<input type="hidden" name="_method" value="PUT">');
|
||||||
|
$('#kt_modal_{{$route[0].'_'.$route[1]}}').modal('show');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('click', '.delete', function (event) {
|
||||||
|
var form = $(this).closest("form");
|
||||||
|
event.preventDefault();
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Are you sure?',
|
||||||
|
text: "You won't be able to revert this!",
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
cancelButtonColor: '#d33',
|
||||||
|
confirmButtonText: 'Yes, delete it!'
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: form.attr('action'),
|
||||||
|
data: form.serialize(), // serializes the form's elements.
|
||||||
|
success: function (data) {
|
||||||
|
toastr.success('{{ucfirst($route[0].' '.$route[1])}} has been deleted.', 'Success!', {timeOut: 5000});
|
||||||
|
LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].ajax.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('change', '.status', function (event) {
|
||||||
|
var form = $(this).closest("form");
|
||||||
|
var _data = form.serializeArray().reduce(function(obj, item) {
|
||||||
|
obj[item.name] = item.value;
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
event.preventDefault();
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: form.attr('action'),
|
||||||
|
data: form.serialize(), // serializes the form's elements.
|
||||||
|
success: function (data) {
|
||||||
|
toastr.success('{{ucfirst($route[1])}} '+_data.name+' status has been changed.', 'Success!', {timeOut: 5000});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
|
||||||
|
@section('styles')
|
||||||
|
<style>
|
||||||
|
.dataTables_filter {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@endsection
|
135
Resources/views/master/index.blade.php
Normal file
135
Resources/views/master/index.blade.php
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
@php
|
||||||
|
$route = explode('.', Route::currentRouteName());
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<x-default-layout>
|
||||||
|
<!--begin::Card-->
|
||||||
|
<div class="card card-xxl-stretch mb-5 mb-xl-8">
|
||||||
|
<!--begin::Card body-->
|
||||||
|
<div class="card-header border-0 pt-5">
|
||||||
|
<div class="card-title align-items-start flex-column">
|
||||||
|
<div class="d-flex align-items-center position-relative my-1">
|
||||||
|
<!--begin::Svg Icon | path: icons/duotune/general/gen021.svg-->
|
||||||
|
<span class="svg-icon svg-icon-1 position-absolute ms-6">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
|
||||||
|
<rect opacity="0.5" x="17.0365" y="15.1223" width="8.15546" height="2" rx="1"
|
||||||
|
transform="rotate(45 17.0365 15.1223)" fill="currentColor"></rect>
|
||||||
|
<path
|
||||||
|
d="M11 19C6.55556 19 3 15.4444 3 11C3 6.55556 6.55556 3 11 3C15.4444 3 19 6.55556 19 11C19 15.4444 15.4444 19 11 19ZM11 5C7.53333 5 5 7.53333 5 11C5 14.4667 7.53333 17 11 17C14.4667 17 17 14.4667 17 11C17 7.53333 14.4667 5 11 5Z"
|
||||||
|
fill="currentColor"></path>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
<!--end::Svg Icon-->
|
||||||
|
<input type="text" id="searchbox"
|
||||||
|
class="form-control form-control-solid border border-gray-300 w-250px ps-15"
|
||||||
|
placeholder="Search {{ ucfirst($route[1]) }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--begin::Export buttons-->
|
||||||
|
<div id="kt_datatable_example_1_export" class="d-none"></div>
|
||||||
|
<!--end::Export buttons-->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card-toolbar">
|
||||||
|
|
||||||
|
<!--begin::Export dropdown-->
|
||||||
|
<button type="button" class="btn btn-light-primary" data-kt-menu-trigger="click"
|
||||||
|
data-kt-menu-placement="bottom-end">
|
||||||
|
<i class="ki-duotone ki-exit-down fs-2"><span class="path1"></span><span class="path2"></span></i>
|
||||||
|
Export Report
|
||||||
|
</button>
|
||||||
|
<!--begin::Menu-->
|
||||||
|
<div id="kt_datatable_example_export_menu"
|
||||||
|
class="menu menu-sub menu-sub-dropdown menu-column menu-rounded menu-gray-600 menu-state-bg-light-primary fw-semibold fs-7 w-200px py-4"
|
||||||
|
data-kt-menu="true">
|
||||||
|
<!--begin::Menu item-->
|
||||||
|
<div class="menu-item px-3">
|
||||||
|
<a href="#" class="menu-link px-3" data-kt-export="copy">
|
||||||
|
Copy to clipboard
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<!--end::Menu item-->
|
||||||
|
<!--begin::Menu item-->
|
||||||
|
<div class="menu-item px-3">
|
||||||
|
<a href="#" class="menu-link px-3" data-kt-export="excel">
|
||||||
|
Export as Excel
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<!--end::Menu item-->
|
||||||
|
<!--begin::Menu item-->
|
||||||
|
<div class="menu-item px-3">
|
||||||
|
<a href="#" class="menu-link px-3" data-kt-export="csv">
|
||||||
|
Export as CSV
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<!--end::Menu item-->
|
||||||
|
<!--begin::Menu item-->
|
||||||
|
<div class="menu-item px-3">
|
||||||
|
<a href="#" class="menu-link px-3" data-kt-export="pdf">
|
||||||
|
Export as PDF
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<!--end::Menu item-->
|
||||||
|
<!--begin::Menu item-->
|
||||||
|
<div class="menu-item px-3">
|
||||||
|
<a href="#" class="menu-link px-3" data-kt-export="print">
|
||||||
|
Print
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<!--end::Menu item-->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--begin::Hide default export buttons-->
|
||||||
|
<div id="kt_datatable_example_buttons" class="d-none"></div>
|
||||||
|
<!--end::Hide default export buttons-->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body pt-6">
|
||||||
|
@include($route[0].'::master._table')
|
||||||
|
@include($route[0].'::master._form')
|
||||||
|
</div>
|
||||||
|
<!--end::Card body-->
|
||||||
|
</div>
|
||||||
|
<!--end::Card-->
|
||||||
|
@push('customscript')
|
||||||
|
<script>
|
||||||
|
$(function () {
|
||||||
|
$(".form_{{$route[0].'_'.$route[1]}}").submit(function (e) {
|
||||||
|
e.preventDefault(); // avoid to execute the actual submit of the form.
|
||||||
|
|
||||||
|
var form = $(this);
|
||||||
|
var actionUrl = form.attr('action');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: actionUrl,
|
||||||
|
data: form.serialize(), // serializes the form's elements.
|
||||||
|
success: function (data) {
|
||||||
|
var _data = JSON.parse(data);
|
||||||
|
toastr.success(_data.message);
|
||||||
|
form[0].reset();
|
||||||
|
LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].ajax.reload();
|
||||||
|
$('#kt_modal_{{$route[0].'_'.$route[1]}}').modal('hide');
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function (data, textStatus, errorThrown) {
|
||||||
|
var errors = data.responseJSON.errors;
|
||||||
|
$.each(errors, function (key, value) {
|
||||||
|
toastr.error(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#kt_modal_{{$route[0].'_'.$route[1]}}').on('hidden.bs.modal', function (e) {
|
||||||
|
$(".form_{{$route[0].'_'.$route[1]}}")[0].reset();
|
||||||
|
$(".form_{{$route[0].'_'.$route[1]}}").attr('action', "{{ route($route[0].'.'.$route[1].'.store') }}");
|
||||||
|
$(".form_{{$route[0].'_'.$route[1]}}").find('input[name="_method"]').remove();
|
||||||
|
$("#title_form").html("Create {{ucfirst($route[1])}}");
|
||||||
|
})
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
</x-default-layout>
|
42
Resources/views/partials/menu/_app.blade.php
Normal file
42
Resources/views/partials/menu/_app.blade.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
@canany(['product.read','product.create','product.update','product.delete'])
|
||||||
|
<!--begin:Menu item-->
|
||||||
|
<div data-kt-menu-trigger="click" class="menu-item menu-accordion {{ $route[0] == 'product' ? 'show' : '' }}">
|
||||||
|
<!--begin:Menu link-->
|
||||||
|
<span class="menu-link">
|
||||||
|
<span class="menu-icon">{!! getIcon('lots-shopping', 'fs-2','duotone') !!}</span>
|
||||||
|
<span class="menu-title">Product</span>
|
||||||
|
<span class="menu-arrow"></span>
|
||||||
|
</span>
|
||||||
|
<!--end:Menu link-->
|
||||||
|
<!--begin:Menu sub-->
|
||||||
|
<div class="menu-sub menu-sub-accordion">
|
||||||
|
<!--begin:Menu item-->
|
||||||
|
<div class="menu-item">
|
||||||
|
<!--begin:Menu link-->
|
||||||
|
<a class="menu-link {{ isset($route[1]) && $route[1] == 'category' ? 'active' : '' }}" href="{{ route('product.category.index') }}">
|
||||||
|
<span class="menu-bullet">
|
||||||
|
<span class="bullet bullet-dot"></span>
|
||||||
|
</span>
|
||||||
|
<span class="menu-title">Category</span>
|
||||||
|
</a>
|
||||||
|
<!--end:Menu link-->
|
||||||
|
</div>
|
||||||
|
<!--end:Menu item-->
|
||||||
|
|
||||||
|
<!--begin:Menu item-->
|
||||||
|
<div class="menu-item">
|
||||||
|
<!--begin:Menu link-->
|
||||||
|
<a class="menu-link {{ isset($route[1]) && $route[1] == 'unit' ? 'active' : '' }}" href="{{ route('product.unit.index') }}">
|
||||||
|
<span class="menu-bullet">
|
||||||
|
<span class="bullet bullet-dot"></span>
|
||||||
|
</span>
|
||||||
|
<span class="menu-title">Unit</span>
|
||||||
|
</a>
|
||||||
|
<!--end:Menu link-->
|
||||||
|
</div>
|
||||||
|
<!--end:Menu item-->
|
||||||
|
</div>
|
||||||
|
<!--end:Menu sub-->
|
||||||
|
</div>
|
||||||
|
<!--end:Menu item-->
|
||||||
|
@endcanany
|
0
Routes/.gitkeep
Normal file
0
Routes/.gitkeep
Normal file
18
Routes/api.php
Normal file
18
Routes/api.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| 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::middleware('auth:api')->get('/product', function (Request $request) {
|
||||||
|
return $request->user();
|
||||||
|
});
|
22
Routes/web.php
Normal file
22
Routes/web.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| 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!
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Modules\Product\Http\Controllers\CategoryController;
|
||||||
|
use Modules\Product\Http\Controllers\UnitController;
|
||||||
|
|
||||||
|
Route::middleware(['auth', 'verified'])->group(function () {
|
||||||
|
Route::prefix('product')->name('product.')->group(function () {
|
||||||
|
Route::resource('unit', UnitController::class);
|
||||||
|
Route::resource('category', CategoryController::class);
|
||||||
|
});
|
||||||
|
});
|
24
composer.json
Normal file
24
composer.json
Normal file
@ -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\\": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
module.json
Normal file
13
module.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "Product",
|
||||||
|
"alias": "product",
|
||||||
|
"description": "",
|
||||||
|
"database": "",
|
||||||
|
"domain": "",
|
||||||
|
"keywords": [],
|
||||||
|
"priority": 0,
|
||||||
|
"providers": [
|
||||||
|
"Modules\\Product\\Providers\\ProductServiceProvider"
|
||||||
|
],
|
||||||
|
"files": []
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user