From 2a2fb1c8567d22cf54c2e1557cbbf539971fd1d9 Mon Sep 17 00:00:00 2001 From: "daeng.deni@dharma.or.id" Date: Sun, 21 May 2023 12:37:35 +0700 Subject: [PATCH] Reformat Codes --- Config/config.php | 6 +- DataTables/PermissionsDataTable.php | 19 +- DataTables/RolesDataTable.php | 181 +++++++------- DataTables/UsersDataTable.php | 174 ++++++------- .../2014_10_12_000000_create_users_table.php | 71 +++--- ...12_100000_create_password_resets_table.php | 63 +++-- ..._08_19_000000_create_failed_jobs_table.php | 71 +++--- ...01_create_personal_access_tokens_table.php | 73 +++--- ..._04_15_221620_create_permission_tables.php | 232 +++++++++--------- ..._225705_create_permission_groups_table.php | 3 +- ..._04_15_225909_update_permissions_table.php | 47 ++-- .../Seeders/UserManagerDatabaseSeeder.php | 38 +-- Database/factories/UserFactory.php | 64 ++--- Entities/Permission.php | 33 +-- Http/Controllers/Auth/AuthApiController.php | 6 +- Http/Controllers/Users/Api/RoleController.php | 5 +- Http/Controllers/Users/UsersController.php | 4 +- Http/Requests/Role/StoreRoleRequest.php | 2 +- Http/Requests/Role/UpdateRoleRequest.php | 2 +- Providers/RouteServiceProvider.php | 118 ++++----- Providers/UserManagerServiceProvider.php | 204 +++++++-------- Resources/views/auth/reset-password.blade.php | 22 +- .../views/users/permissions/_action.blade.php | 14 +- .../users/permissions/_checkbox.blade.php | 2 +- .../views/users/permissions/_form.blade.php | 78 +++--- .../views/users/permissions/_table.blade.php | 5 +- Resources/views/users/roles/_action.blade.php | 14 +- .../views/users/roles/_editform.blade.php | 19 +- Resources/views/users/roles/_form.blade.php | 85 +++---- Resources/views/users/roles/_table.blade.php | 3 +- Resources/views/users/users/_action.blade.php | 14 +- Resources/views/users/users/_table.blade.php | 11 +- Routes/auth.php | 80 +++--- composer.json | 1 - 34 files changed, 885 insertions(+), 879 deletions(-) diff --git a/Config/config.php b/Config/config.php index 16ef003..4a39243 100644 --- a/Config/config.php +++ b/Config/config.php @@ -1,5 +1,5 @@ 'Usermanager' -]; + return [ + 'name' => 'Usermanager' + ]; diff --git a/DataTables/PermissionsDataTable.php b/DataTables/PermissionsDataTable.php index 5dc7325..3b239dc 100644 --- a/DataTables/PermissionsDataTable.php +++ b/DataTables/PermissionsDataTable.php @@ -3,15 +3,16 @@ namespace Modules\Usermanager\DataTables; use Modules\Usermanager\Entities\PermissionGroup; - use Yajra\DataTables\Html\Column; - use Yajra\DataTables\Services\DataTable; + use Yajra\DataTables\Html\Column; + use Yajra\DataTables\Services\DataTable; - class PermissionsDataTable extends DataTable + class PermissionsDataTable extends DataTable { /** * Build DataTable class. * * @param mixed $query Results from query() method. + * * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) @@ -24,13 +25,13 @@ $query->where('name', 'like', "%" . $search['value'] . "%"); } }) - ->rawColumns(['action','role']) + ->rawColumns(['action', 'role']) ->addIndexColumn() ->addColumn('name', function (PermissionGroup $model) { return $model->name; }) - ->addColumn('role', function (PermissionGroup $model){ - $role = $model->roles($model); + ->addColumn('role', function (PermissionGroup $model) { + $role = $model->roles($model); return view('usermanager::users.permissions._checkbox', compact('role')); }) ->addColumn('action', function (PermissionGroup $model) { @@ -61,7 +62,7 @@ ->setTableId('user-permissions-table') ->columns($this->getColumns()) ->minifiedAjax() - ->orderBy(1,'asc') + ->orderBy(1, 'asc') ->stateSave(false) ->responsive() ->autoWidth(false) @@ -94,9 +95,11 @@ /** * Get filename for export + * * @return string */ - protected function filename() : string + protected function filename() + : string { return 'Permissions_' . date('YmdHis'); } diff --git a/DataTables/RolesDataTable.php b/DataTables/RolesDataTable.php index 8f29a80..cbf8b40 100644 --- a/DataTables/RolesDataTable.php +++ b/DataTables/RolesDataTable.php @@ -2,95 +2,98 @@ namespace Modules\Usermanager\DataTables; -use Spatie\Permission\Models\Role; -use Yajra\DataTables\Html\Column; -use Yajra\DataTables\Services\DataTable; + use Spatie\Permission\Models\Role; + use Yajra\DataTables\Html\Column; + use Yajra\DataTables\Services\DataTable; -class RolesDataTable extends DataTable -{ - /** - * Build DataTable class. - * - * @param mixed $query Results from query() method. - * @return \Yajra\DataTables\DataTableAbstract - */ - public function dataTable($query) + class RolesDataTable extends DataTable { - return datatables() - ->eloquent($query) - ->rawColumns(['action']) - ->addIndexColumn() - ->filter(function ($query) { - if (request()->has('search')) { - $search = request()->get('search'); - $query->where('name', 'like', "%" . $search['value'] . "%"); - } - }) - ->addColumn('action', function (Role $model) { - return view('usermanager::users.roles._action', compact('model')); - }); + /** + * Build DataTable class. + * + * @param mixed $query Results from query() method. + * + * @return \Yajra\DataTables\DataTableAbstract + */ + public function dataTable($query) + { + return datatables() + ->eloquent($query) + ->rawColumns(['action']) + ->addIndexColumn() + ->filter(function ($query) { + if (request()->has('search')) { + $search = request()->get('search'); + $query->where('name', 'like', "%" . $search['value'] . "%"); + } + }) + ->addColumn('action', function (Role $model) { + return view('usermanager::users.roles._action', compact('model')); + }); + } + + /** + * Get query source of dataTable. + * + * @param \Spatie\Permission\Models\Role $model + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function query(Role $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('user-roles-table') + ->columns($this->getColumns()) + ->minifiedAjax() + ->orderBy(1, 'asc') + ->stateSave(false) + ->responsive() + ->autoWidth(false) + ->parameters([ + 'scrollX' => true, + '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'), + Column::computed('action') + ->exportable(false) + ->printable(false) + ->addClass('text-center') + ->responsivePriority(-1), + + ]; + } + + /** + * Get filename for export. + * + * @return string + */ + protected function filename() + : string + { + return 'Roles_' . date('YmdHis'); + } } - - /** - * Get query source of dataTable. - * - * @param \Spatie\Permission\Models\Role $model - * @return \Illuminate\Database\Eloquent\Builder - */ - public function query(Role $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('user-roles-table') - ->columns($this->getColumns()) - ->minifiedAjax() - ->orderBy(1,'asc') - ->stateSave(false) - ->responsive() - ->autoWidth(false) - ->parameters([ - 'scrollX' => true, - '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'), - Column::computed('action') - ->exportable(false) - ->printable(false) - ->addClass('text-center') - ->responsivePriority(-1), - - ]; - } - - /** - * Get filename for export. - * - * @return string - */ - protected function filename() : string - { - return 'Roles_' . date('YmdHis'); - } -} diff --git a/DataTables/UsersDataTable.php b/DataTables/UsersDataTable.php index bf59b92..18280ef 100644 --- a/DataTables/UsersDataTable.php +++ b/DataTables/UsersDataTable.php @@ -2,97 +2,99 @@ namespace Modules\Usermanager\DataTables; -use Modules\Usermanager\Entities\User; -use Yajra\DataTables\Html\Column; -use Yajra\DataTables\Services\DataTable; + use Modules\Usermanager\Entities\User; + use Yajra\DataTables\Html\Column; + use Yajra\DataTables\Services\DataTable; -class UsersDataTable extends DataTable -{ - /** - * Build DataTable class. - * - * @param mixed $query Results from query() method. - * @return \Yajra\DataTables\DataTableAbstract - */ - public function dataTable($query) + class UsersDataTable 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'] . "%") - ->orWhere('email', 'like', "%" . $search['value'] . "%"); - } - }) - ->rawColumns(['action']) - ->addIndexColumn() - ->addColumn('action', function (User $model) { - return view('usermanager::users.users._action', compact('model')); - }); - } + return datatables() + ->eloquent($query) + ->filter(function ($query) { + $search = request()->get('search'); + if ($search['value'] !== "") { + $query->where('name', 'like', "%" . $search['value'] . "%") + ->orWhere('email', 'like', "%" . $search['value'] . "%"); + } + }) + ->rawColumns(['action']) + ->addIndexColumn() + ->addColumn('action', function (User $model) { + return view('usermanager::users.users._action', compact('model')); + }); + } - /** - * Get query source of dataTable. - * - * @param \Modules\Usermanager\Entities\User $model - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function query(User $model) - { - return $model->newQuery(); - } + /** + * Get query source of dataTable. + * + * @param \Modules\Usermanager\Entities\User $model + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function query(User $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('user-users-table') - ->columns($this->getColumns()) - ->minifiedAjax() - ->orderBy(1,'asc') - ->stateSave(false) - ->responsive() - ->autoWidth(false) - ->parameters([ - 'scrollX' => true, - 'drawCallback' => 'function() { KTMenu.createInstances(); }', - ]) - ->addTableClass('align-middle table-row-dashed fs-6 gy-5'); - } + /** + * Optional method if you want to use html builder. + * + * @return \Yajra\DataTables\Html\Builder + */ + public function html() + { + return $this->builder() + ->setTableId('user-users-table') + ->columns($this->getColumns()) + ->minifiedAjax() + ->orderBy(1, 'asc') + ->stateSave(false) + ->responsive() + ->autoWidth(false) + ->parameters([ + 'scrollX' => true, + '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::make('email'), - Column::computed('action') - ->exportable(false) - ->printable(false) - ->addClass('text-center') - ->responsivePriority(-1), - ]; - } + /** + * Get columns. + * + * @return array + */ + protected function getColumns() + { + return [ + Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false), + Column::make('name')->title(__('Name')), + Column::make('email'), + Column::computed('action') + ->exportable(false) + ->printable(false) + ->addClass('text-center') + ->responsivePriority(-1), + ]; + } - /** - * Get filename for export. - * - * @return string - */ - protected function filename() : string - { - return 'Users_' . date('YmdHis'); + /** + * Get filename for export. + * + * @return string + */ + protected function filename() + : string + { + return 'Users_' . date('YmdHis'); + } } -} diff --git a/Database/Migrations/2014_10_12_000000_create_users_table.php b/Database/Migrations/2014_10_12_000000_create_users_table.php index d51e598..115bd9b 100644 --- a/Database/Migrations/2014_10_12_000000_create_users_table.php +++ b/Database/Migrations/2014_10_12_000000_create_users_table.php @@ -1,41 +1,40 @@ id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - $table->softDeletes(); + return new class extends Migration { + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('users', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->string('email')->unique(); + $table->timestamp('email_verified_at')->nullable(); + $table->string('password'); + $table->rememberToken(); + $table->timestamps(); + $table->softDeletes(); - $table->unsignedBigInteger('created_by')->nullable(); - $table->unsignedBigInteger('updated_by')->nullable(); - $table->unsignedBigInteger('deleted_by')->nullable(); - }); - } + $table->unsignedBigInteger('created_by')->nullable(); + $table->unsignedBigInteger('updated_by')->nullable(); + $table->unsignedBigInteger('deleted_by')->nullable(); + }); + } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('users'); - } -}; + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('users'); + } + }; diff --git a/Database/Migrations/2014_10_12_100000_create_password_resets_table.php b/Database/Migrations/2014_10_12_100000_create_password_resets_table.php index 3d3536e..69d43ef 100644 --- a/Database/Migrations/2014_10_12_100000_create_password_resets_table.php +++ b/Database/Migrations/2014_10_12_100000_create_password_resets_table.php @@ -1,37 +1,36 @@ string('email')->index(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - $table->softDeletes(); + return new class extends Migration { + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('password_resets', function (Blueprint $table) { + $table->string('email')->index(); + $table->string('token'); + $table->timestamp('created_at')->nullable(); + $table->softDeletes(); - $table->unsignedBigInteger('created_by')->nullable(); - $table->unsignedBigInteger('updated_by')->nullable(); - $table->unsignedBigInteger('deleted_by')->nullable(); - }); - } + $table->unsignedBigInteger('created_by')->nullable(); + $table->unsignedBigInteger('updated_by')->nullable(); + $table->unsignedBigInteger('deleted_by')->nullable(); + }); + } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('password_resets'); - } -}; + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('password_resets'); + } + }; diff --git a/Database/Migrations/2019_08_19_000000_create_failed_jobs_table.php b/Database/Migrations/2019_08_19_000000_create_failed_jobs_table.php index 579b7f6..1d9d4ed 100644 --- a/Database/Migrations/2019_08_19_000000_create_failed_jobs_table.php +++ b/Database/Migrations/2019_08_19_000000_create_failed_jobs_table.php @@ -1,41 +1,40 @@ id(); - $table->string('uuid')->unique(); - $table->text('connection'); - $table->text('queue'); - $table->longText('payload'); - $table->longText('exception'); - $table->timestamp('failed_at')->useCurrent(); - $table->softDeletes(); + return new class extends Migration { + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('failed_jobs', function (Blueprint $table) { + $table->id(); + $table->string('uuid')->unique(); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + $table->softDeletes(); - $table->unsignedBigInteger('created_by')->nullable(); - $table->unsignedBigInteger('updated_by')->nullable(); - $table->unsignedBigInteger('deleted_by')->nullable(); - }); - } + $table->unsignedBigInteger('created_by')->nullable(); + $table->unsignedBigInteger('updated_by')->nullable(); + $table->unsignedBigInteger('deleted_by')->nullable(); + }); + } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('failed_jobs'); - } -}; + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('failed_jobs'); + } + }; diff --git a/Database/Migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/Database/Migrations/2019_12_14_000001_create_personal_access_tokens_table.php index b1259f9..bc0e954 100644 --- a/Database/Migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ b/Database/Migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -1,42 +1,41 @@ id(); - $table->morphs('tokenable'); - $table->string('name'); - $table->string('token', 64)->unique(); - $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamp('expires_at')->nullable(); - $table->timestamps(); - $table->softDeletes(); + return new class extends Migration { + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('personal_access_tokens', function (Blueprint $table) { + $table->id(); + $table->morphs('tokenable'); + $table->string('name'); + $table->string('token', 64)->unique(); + $table->text('abilities')->nullable(); + $table->timestamp('last_used_at')->nullable(); + $table->timestamp('expires_at')->nullable(); + $table->timestamps(); + $table->softDeletes(); - $table->unsignedBigInteger('created_by')->nullable(); - $table->unsignedBigInteger('updated_by')->nullable(); - $table->unsignedBigInteger('deleted_by')->nullable(); - }); - } + $table->unsignedBigInteger('created_by')->nullable(); + $table->unsignedBigInteger('updated_by')->nullable(); + $table->unsignedBigInteger('deleted_by')->nullable(); + }); + } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('personal_access_tokens'); - } -}; + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('personal_access_tokens'); + } + }; diff --git a/Database/Migrations/2023_04_15_221620_create_permission_tables.php b/Database/Migrations/2023_04_15_221620_create_permission_tables.php index 04c3278..c7806b5 100644 --- a/Database/Migrations/2023_04_15_221620_create_permission_tables.php +++ b/Database/Migrations/2023_04_15_221620_create_permission_tables.php @@ -1,141 +1,141 @@ bigIncrements('id'); // permission id - $table->string('name'); // For MySQL 8.0 use string('name', 125); - $table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125); - $table->timestamps(); - - $table->unique(['name', 'guard_name']); - }); - - Schema::create($tableNames['roles'], function (Blueprint $table) use ($teams, $columnNames) { - $table->bigIncrements('id'); // role id - if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing - $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable(); - $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); + if (empty($tableNames)) { + throw new Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.'); } - $table->string('name'); // For MySQL 8.0 use string('name', 125); - $table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125); - $table->timestamps(); - if ($teams || config('permission.testing')) { - $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); - } else { + if ($teams && empty($columnNames['team_foreign_key'] ?? null)) { + throw new Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.'); + } + + Schema::create($tableNames['permissions'], function (Blueprint $table) { + $table->bigIncrements('id'); // permission id + $table->string('name'); // For MySQL 8.0 use string('name', 125); + $table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125); + $table->timestamps(); + $table->unique(['name', 'guard_name']); - } - }); + }); - Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) { - $table->unsignedBigInteger(PermissionRegistrar::$pivotPermission); + Schema::create($tableNames['roles'], function (Blueprint $table) use ($teams, $columnNames) { + $table->bigIncrements('id'); // role id + if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing + $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable(); + $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); + } + $table->string('name'); // For MySQL 8.0 use string('name', 125); + $table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125); + $table->timestamps(); + if ($teams || config('permission.testing')) { + $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); + } else { + $table->unique(['name', 'guard_name']); + } + }); - $table->string('model_type'); - $table->unsignedBigInteger($columnNames['model_morph_key']); - $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); + Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) { + $table->unsignedBigInteger(PermissionRegistrar::$pivotPermission); - $table->foreign(PermissionRegistrar::$pivotPermission) - ->references('id') // permission id - ->on($tableNames['permissions']) - ->onDelete('cascade'); - if ($teams) { - $table->unsignedBigInteger($columnNames['team_foreign_key']); - $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); - $table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'], - 'model_has_permissions_permission_model_type_primary'); - } else { - $table->primary([PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'], - 'model_has_permissions_permission_model_type_primary'); - } + $table->foreign(PermissionRegistrar::$pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->onDelete('cascade'); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); - }); + $table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } else { + $table->primary([PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } - Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) { - $table->unsignedBigInteger(PermissionRegistrar::$pivotRole); + }); - $table->string('model_type'); - $table->unsignedBigInteger($columnNames['model_morph_key']); - $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); + Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) { + $table->unsignedBigInteger(PermissionRegistrar::$pivotRole); - $table->foreign(PermissionRegistrar::$pivotRole) - ->references('id') // role id - ->on($tableNames['roles']) - ->onDelete('cascade'); - if ($teams) { - $table->unsignedBigInteger($columnNames['team_foreign_key']); - $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); - $table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'], - 'model_has_roles_role_model_type_primary'); - } else { - $table->primary([PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'], - 'model_has_roles_role_model_type_primary'); - } - }); + $table->foreign(PermissionRegistrar::$pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->onDelete('cascade'); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); - Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { - $table->unsignedBigInteger(PermissionRegistrar::$pivotPermission); - $table->unsignedBigInteger(PermissionRegistrar::$pivotRole); + $table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } else { + $table->primary([PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } + }); - $table->foreign(PermissionRegistrar::$pivotPermission) - ->references('id') // permission id - ->on($tableNames['permissions']) - ->onDelete('cascade'); + Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { + $table->unsignedBigInteger(PermissionRegistrar::$pivotPermission); + $table->unsignedBigInteger(PermissionRegistrar::$pivotRole); - $table->foreign(PermissionRegistrar::$pivotRole) - ->references('id') // role id - ->on($tableNames['roles']) - ->onDelete('cascade'); + $table->foreign(PermissionRegistrar::$pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->onDelete('cascade'); - $table->primary([PermissionRegistrar::$pivotPermission, PermissionRegistrar::$pivotRole], 'role_has_permissions_permission_id_role_id_primary'); - }); + $table->foreign(PermissionRegistrar::$pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->onDelete('cascade'); - app('cache') - ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) - ->forget(config('permission.cache.key')); - } + $table->primary([PermissionRegistrar::$pivotPermission, PermissionRegistrar::$pivotRole], 'role_has_permissions_permission_id_role_id_primary'); + }); - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - $tableNames = config('permission.table_names'); - - if (empty($tableNames)) { - throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); + app('cache') + ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) + ->forget(config('permission.cache.key')); } - Schema::drop($tableNames['role_has_permissions']); - Schema::drop($tableNames['model_has_roles']); - Schema::drop($tableNames['model_has_permissions']); - Schema::drop($tableNames['roles']); - Schema::drop($tableNames['permissions']); + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $tableNames = config('permission.table_names'); + + if (empty($tableNames)) { + throw new Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); + } + + Schema::drop($tableNames['role_has_permissions']); + Schema::drop($tableNames['model_has_roles']); + Schema::drop($tableNames['model_has_permissions']); + Schema::drop($tableNames['roles']); + Schema::drop($tableNames['permissions']); + } } -} diff --git a/Database/Migrations/2023_04_15_225705_create_permission_groups_table.php b/Database/Migrations/2023_04_15_225705_create_permission_groups_table.php index 7842625..eb2bcc2 100644 --- a/Database/Migrations/2023_04_15_225705_create_permission_groups_table.php +++ b/Database/Migrations/2023_04_15_225705_create_permission_groups_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; - return new class extends Migration - { + return new class extends Migration { /** * Run the migrations. * diff --git a/Database/Migrations/2023_04_15_225909_update_permissions_table.php b/Database/Migrations/2023_04_15_225909_update_permissions_table.php index 3fb30a1..2339961 100644 --- a/Database/Migrations/2023_04_15_225909_update_permissions_table.php +++ b/Database/Migrations/2023_04_15_225909_update_permissions_table.php @@ -1,27 +1,28 @@ foreignIdFor(PermissionGroup::class); - }); - } + return new class extends Migration { + /** + * Run the migrations. + */ + public function up() + : void + { + Schema::table('permissions', function ($table) { + $table->foreignIdFor(PermissionGroup::class); + }); + } - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropForeignKey('permission_group_id'); - Schema::dropColumn('permission_group_id'); - } -}; + /** + * Reverse the migrations. + */ + public function down() + : void + { + Schema::dropForeignKey('permission_group_id'); + Schema::dropColumn('permission_group_id'); + } + }; diff --git a/Database/Seeders/UserManagerDatabaseSeeder.php b/Database/Seeders/UserManagerDatabaseSeeder.php index 19a3d1f..83701ab 100644 --- a/Database/Seeders/UserManagerDatabaseSeeder.php +++ b/Database/Seeders/UserManagerDatabaseSeeder.php @@ -1,26 +1,26 @@ call([ - PermissionGroupSeeder::class, - RolesSeeder::class, - PermissionsSeeder::class, - UsersSeeder::class - ]); + $this->call([ + PermissionGroupSeeder::class, + RolesSeeder::class, + PermissionsSeeder::class, + UsersSeeder::class + ]); + } } -} diff --git a/Database/factories/UserFactory.php b/Database/factories/UserFactory.php index 18472e7..40598d1 100644 --- a/Database/factories/UserFactory.php +++ b/Database/factories/UserFactory.php @@ -1,40 +1,40 @@ - */ -class UserFactory extends Factory -{ - /** - * Define the model's default state. - * - * @return array - */ - public function definition() - { - return [ - 'name' => fake()->name(), - 'email' => fake()->unique()->safeEmail(), - 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password - 'remember_token' => Str::random(10), - ]; - } + use Illuminate\Database\Eloquent\Factories\Factory; + use Illuminate\Support\Str; /** - * Indicate that the model's email address should be unverified. - * - * @return static + * @extends \Illuminate\Database\Eloquent\Factories\Factory<\Modules\Usermanager\Entities\User> */ - public function unverified() + class UserFactory extends Factory { - return $this->state(fn (array $attributes) => [ - 'email_verified_at' => null, - ]); + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + 'name' => fake()->name(), + 'email' => fake()->unique()->safeEmail(), + 'email_verified_at' => now(), + 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'remember_token' => Str::random(10), + ]; + } + + /** + * Indicate that the model's email address should be unverified. + * + * @return static + */ + public function unverified() + { + return $this->state(fn(array $attributes) => [ + 'email_verified_at' => null, + ]); + } } -} diff --git a/Entities/Permission.php b/Entities/Permission.php index 060cab7..57c8f67 100644 --- a/Entities/Permission.php +++ b/Entities/Permission.php @@ -1,23 +1,24 @@ logAll() - ->useLogName('master data'); - } + use LogsActivity; - public function group() - { - return $this->hasOne(PermissionGroup::class); + public function getActivitylogOptions() + : LogOptions + { + return LogOptions::defaults()->logAll() + ->useLogName('master data'); + } + + public function group() + { + return $this->hasOne(PermissionGroup::class); + } } -} diff --git a/Http/Controllers/Auth/AuthApiController.php b/Http/Controllers/Auth/AuthApiController.php index 965228d..3db5938 100644 --- a/Http/Controllers/Auth/AuthApiController.php +++ b/Http/Controllers/Auth/AuthApiController.php @@ -16,7 +16,8 @@ * * @return \Illuminate\Http\Response */ - public function register(Request $request): JsonResponse + public function register(Request $request) + : JsonResponse { $validator = Validator::make($request->all(), [ 'name' => 'required', @@ -43,7 +44,8 @@ * * @return \Illuminate\Http\Response */ - public function login(Request $request): JsonResponse + public function login(Request $request) + : JsonResponse { if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) { $user = Auth::user(); diff --git a/Http/Controllers/Users/Api/RoleController.php b/Http/Controllers/Users/Api/RoleController.php index d6be4ef..244621e 100644 --- a/Http/Controllers/Users/Api/RoleController.php +++ b/Http/Controllers/Users/Api/RoleController.php @@ -39,7 +39,7 @@ // Store the Role... if ($validated) { try { - if(!isset($validated['guard_name'])){ + if (!isset($validated['guard_name'])) { $validated['guard_name'] = 'default'; } @@ -53,7 +53,6 @@ } - return $this->sendResponse($role, 'Role created successfully.'); } catch (Exception $e) { return $this->sendError($e->getMessage(), $e->getCode()); @@ -72,7 +71,7 @@ // Store the Role... if ($validated) { try { - if(!isset($validated['guard_name'])){ + if (!isset($validated['guard_name'])) { $validated['guard_name'] = 'default'; } diff --git a/Http/Controllers/Users/UsersController.php b/Http/Controllers/Users/UsersController.php index c1e61bd..74daf0b 100644 --- a/Http/Controllers/Users/UsersController.php +++ b/Http/Controllers/Users/UsersController.php @@ -38,8 +38,8 @@ addVendor('chained-select'); - $roles = Role::all(); - return $dataTable->render('usermanager::users.users.index', compact( 'roles')); + $roles = Role::all(); + return $dataTable->render('usermanager::users.users.index', compact('roles')); } /** diff --git a/Http/Requests/Role/StoreRoleRequest.php b/Http/Requests/Role/StoreRoleRequest.php index 7aab4e7..2e4269b 100644 --- a/Http/Requests/Role/StoreRoleRequest.php +++ b/Http/Requests/Role/StoreRoleRequest.php @@ -28,7 +28,7 @@ : array { return [ - 'name' => 'required|max:100|unique:roles,name', + 'name' => 'required|max:100|unique:roles,name', 'guard_name' => 'nullable|max:100|string' ]; } diff --git a/Http/Requests/Role/UpdateRoleRequest.php b/Http/Requests/Role/UpdateRoleRequest.php index 95e7c42..45f1cd6 100644 --- a/Http/Requests/Role/UpdateRoleRequest.php +++ b/Http/Requests/Role/UpdateRoleRequest.php @@ -28,7 +28,7 @@ : array { return [ - 'name' => 'required|max:100|unique:roles,name,' . $this->role->id, + 'name' => 'required|max:100|unique:roles,name,' . $this->role->id, 'guard_name' => 'nullable|max:100|string' ]; } diff --git a/Providers/RouteServiceProvider.php b/Providers/RouteServiceProvider.php index 5c9f0f7..dda6de7 100644 --- a/Providers/RouteServiceProvider.php +++ b/Providers/RouteServiceProvider.php @@ -1,68 +1,68 @@ mapApiRoutes(); - $this->mapWebRoutes(); - } + /** + * Called before routes are registered. + * + * Register any model bindings or pattern based filters. + * + * @return void + */ + public function boot() + { + parent::boot(); + } - /** - * 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('Usermanager', '/Routes/web.php')); - } + /** + * Define the routes for the application. + * + * @return void + */ + public function map() + { + $this->mapApiRoutes(); + $this->mapWebRoutes(); + } - /** - * 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('Usermanager', '/Routes/api.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('Usermanager', '/Routes/api.php')); + } + + /** + * 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('Usermanager', '/Routes/web.php')); + } } -} diff --git a/Providers/UserManagerServiceProvider.php b/Providers/UserManagerServiceProvider.php index 7bf3564..ad63666 100644 --- a/Providers/UserManagerServiceProvider.php +++ b/Providers/UserManagerServiceProvider.php @@ -1,114 +1,116 @@ registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); - } + /** + * @var string $moduleName + */ + protected $moduleName = 'Usermanager'; - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } + /** + * @var string $moduleNameLower + */ + protected $moduleNameLower = 'usermanager'; - /** - * 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')); + /** + * Boot the application events. + * + * @return void + */ + public function boot() + { + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); } - } - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/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')); } } - return $paths; + + /** + * 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); + } + + 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; + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->app->register(RouteServiceProvider::class); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } } -} diff --git a/Resources/views/auth/reset-password.blade.php b/Resources/views/auth/reset-password.blade.php index 6b0d9b1..ce69b79 100644 --- a/Resources/views/auth/reset-password.blade.php +++ b/Resources/views/auth/reset-password.blade.php @@ -2,7 +2,7 @@ - + @@ -14,31 +14,31 @@
- + - + - +
- + - + - +
- + + type="password" + name="password_confirmation" required/> - +
diff --git a/Resources/views/users/permissions/_action.blade.php b/Resources/views/users/permissions/_action.blade.php index 3ea2ecb..e18db53 100644 --- a/Resources/views/users/permissions/_action.blade.php +++ b/Resources/views/users/permissions/_action.blade.php @@ -2,12 +2,12 @@ $route = explode('.', Route::currentRouteName()); @endphp
- - {!! getIcon("pencil", "fs-1 text-info","duotune") !!} - + + {!! 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() !!} + {!! 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/users/permissions/_checkbox.blade.php b/Resources/views/users/permissions/_checkbox.blade.php index 04631f2..76afd5d 100644 --- a/Resources/views/users/permissions/_checkbox.blade.php +++ b/Resources/views/users/permissions/_checkbox.blade.php @@ -15,7 +15,7 @@ @endphp @foreach($role as $row) - {{ $row->name }} + {{ $row->name }} @php $i++ @endphp @endforeach diff --git a/Resources/views/users/permissions/_form.blade.php b/Resources/views/users/permissions/_form.blade.php index 7e532ab..1df286d 100644 --- a/Resources/views/users/permissions/_form.blade.php +++ b/Resources/views/users/permissions/_form.blade.php @@ -2,31 +2,31 @@ $route = explode('.', Route::currentRouteName()); @endphp - + diff --git a/Resources/views/users/permissions/_table.blade.php b/Resources/views/users/permissions/_table.blade.php index 1d8b2af..880d898 100644 --- a/Resources/views/users/permissions/_table.blade.php +++ b/Resources/views/users/permissions/_table.blade.php @@ -59,7 +59,7 @@ }); }); - LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('click','.kt_edit_form',function(event){ + LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('click', '.kt_edit_form', function (event) { event.preventDefault(); $.ajax({ url: $(this).attr('href'), @@ -93,8 +93,7 @@ type: "POST", url: form.attr('action'), data: form.serialize(), // serializes the form's elements. - success: function(data) - { + success: function (data) { toastr.success('{{ucfirst($route[0].' '.$route[1])}} has been deleted.', 'Success!', {timeOut: 5000}); LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].ajax.reload(); } diff --git a/Resources/views/users/roles/_action.blade.php b/Resources/views/users/roles/_action.blade.php index 7c24f5b..f425480 100644 --- a/Resources/views/users/roles/_action.blade.php +++ b/Resources/views/users/roles/_action.blade.php @@ -2,12 +2,12 @@ $route = explode('.', Route::currentRouteName()); @endphp
- - {!! getIcon("pencil", "fs-1 text-info","duotune") !!} - + + {!! 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() !!} + {!! 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/users/roles/_editform.blade.php b/Resources/views/users/roles/_editform.blade.php index 6c382a9..d5cb456 100644 --- a/Resources/views/users/roles/_editform.blade.php +++ b/Resources/views/users/roles/_editform.blade.php @@ -1,7 +1,7 @@
-@method('PUT') -{{ csrf_field() }} - + @method('PUT') + {{ csrf_field() }} +
@error('name')
{{ $message }}
- @enderror - + @enderror +
@@ -36,11 +36,12 @@ Administrator/Superuser Access - + + @@ -57,8 +58,8 @@
- @foreach($group->getpermissionsByGroupId($group->id) as $permission) - + @foreach($group->getpermissionsByGroupId($group->id) as $permission) +
diff --git a/Resources/views/users/roles/_table.blade.php b/Resources/views/users/roles/_table.blade.php index 99766ac..7d03cb7 100644 --- a/Resources/views/users/roles/_table.blade.php +++ b/Resources/views/users/roles/_table.blade.php @@ -76,8 +76,7 @@ type: "POST", url: form.attr('action'), data: form.serialize(), // serializes the form's elements. - success: function(data) - { + success: function (data) { toastr.success('{{ucfirst($route[0].' '.$route[1])}} has been deleted.', 'Success!', {timeOut: 5000}); LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].ajax.reload(); } diff --git a/Resources/views/users/users/_action.blade.php b/Resources/views/users/users/_action.blade.php index dc1a612..3e0dde9 100644 --- a/Resources/views/users/users/_action.blade.php +++ b/Resources/views/users/users/_action.blade.php @@ -2,12 +2,12 @@ $route = explode('.', Route::currentRouteName()); @endphp
- - {!! getIcon("pencil", "fs-1 text-info","duotune") !!} - + + {!! 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() !!} + {!! 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/users/users/_table.blade.php b/Resources/views/users/users/_table.blade.php index eef1735..843dfd4 100644 --- a/Resources/views/users/users/_table.blade.php +++ b/Resources/views/users/users/_table.blade.php @@ -59,7 +59,7 @@ }); }); - LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('click','.kt_edit_form',function(event){ + LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('click', '.kt_edit_form', function (event) { event.preventDefault(); $.ajax({ url: $(this).attr('href'), @@ -72,11 +72,11 @@ $('#{{$route[0].'_'.$route[1]}}_name').val(response.data.name); $('#{{$route[0].'_'.$route[1]}}_email').val(response.data.email); - if(response.data.roles.length > 0){ + if (response.data.roles.length > 0) { var role = response.data.roles[0].name; - var _role = role.replace(' ','-').toLowerCase(); + var _role = role.replace(' ', '-').toLowerCase(); - $("#role_"+_role).prop('checked', true); + $("#role_" + _role).prop('checked', true); } $('.form_{{$route[0].'_'.$route[1]}}').attr('action', '{{ URL::to('/'.$route[0].'/'.$route[1].'/') }}/' + response.data.id).append(''); @@ -102,8 +102,7 @@ type: "POST", url: form.attr('action'), data: form.serialize(), // serializes the form's elements. - success: function(data) - { + success: function (data) { toastr.success('{{ucfirst($route[0].' '.$route[1])}} has been deleted.', 'Success!', {timeOut: 5000}); LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].ajax.reload(); } diff --git a/Routes/auth.php b/Routes/auth.php index 70a65da..3f5ea97 100644 --- a/Routes/auth.php +++ b/Routes/auth.php @@ -1,56 +1,56 @@ group(function () { - Route::get('register', [RegisteredUserController::class, 'create']) - ->name('register'); + Route::middleware('guest')->group(function () { + Route::get('register', [RegisteredUserController::class, 'create']) + ->name('register'); - Route::post('register', [RegisteredUserController::class, 'store']); + Route::post('register', [RegisteredUserController::class, 'store']); - Route::get('login', [AuthenticatedSessionController::class, 'create']) - ->name('login'); + Route::get('login', [AuthenticatedSessionController::class, 'create']) + ->name('login'); - Route::post('login', [AuthenticatedSessionController::class, 'store']); + Route::post('login', [AuthenticatedSessionController::class, 'store']); - Route::get('forgot-password', [PasswordResetLinkController::class, 'create']) - ->name('password.request'); + Route::get('forgot-password', [PasswordResetLinkController::class, 'create']) + ->name('password.request'); - Route::post('forgot-password', [PasswordResetLinkController::class, 'store']) - ->name('password.email'); + Route::post('forgot-password', [PasswordResetLinkController::class, 'store']) + ->name('password.email'); - Route::get('reset-password/{token}', [NewPasswordController::class, 'create']) - ->name('password.reset'); + Route::get('reset-password/{token}', [NewPasswordController::class, 'create']) + ->name('password.reset'); - Route::post('reset-password', [NewPasswordController::class, 'store']) - ->name('password.update'); -}); + Route::post('reset-password', [NewPasswordController::class, 'store']) + ->name('password.update'); + }); -Route::middleware('auth')->group(function () { - Route::get('verify-email', [EmailVerificationPromptController::class, '__invoke']) - ->name('verification.notice'); + Route::middleware('auth')->group(function () { + Route::get('verify-email', [EmailVerificationPromptController::class, '__invoke']) + ->name('verification.notice'); - Route::get('verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke']) - ->middleware(['signed', 'throttle:6,1']) - ->name('verification.verify'); + Route::get('verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke']) + ->middleware(['signed', 'throttle:6,1']) + ->name('verification.verify'); - Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store']) - ->middleware('throttle:6,1') - ->name('verification.send'); + Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store']) + ->middleware('throttle:6,1') + ->name('verification.send'); - Route::get('confirm-password', [ConfirmablePasswordController::class, 'show']) - ->name('password.confirm'); + Route::get('confirm-password', [ConfirmablePasswordController::class, 'show']) + ->name('password.confirm'); - Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']); + Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']); - Route::get('logout', [AuthenticatedSessionController::class, 'destroy']) - ->name('logout'); -}); + Route::get('logout', [AuthenticatedSessionController::class, 'destroy']) + ->name('logout'); + }); diff --git a/composer.json b/composer.json index 01c1b51..08582c0 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,6 @@ "laravel": { "providers": [], "aliases": { - } } },