diff --git a/backend/app/Admin/Controllers/ExpertManagementController.php b/backend/app/Admin/Controllers/ExpertManagementController.php new file mode 100644 index 00000000..6591a8a8 --- /dev/null +++ b/backend/app/Admin/Controllers/ExpertManagementController.php @@ -0,0 +1,114 @@ +json($data); + } + + /** + * Store a newly created resource in storage. + */ + public function store(StoreRequest $request): JsonResponse + { + $province = Province::query()->find($request->province_id); + $city = City::query()->find($request->city_id); + + Expert::query()->create([ + 'username' => $request->username, + 'first_name' => $request->first_name, + 'last_name' => $request->last_name, + 'national_id' => $request->national_id, + 'password' => Hash::make($request->password), + 'email' => $request->email, + 'phone_number' => $request->phone_number, + 'province_id' => $request->province_id, + 'province_name' => $province->name, + 'city_id' => $request->city_id, + 'city_name' => $city->name, + ]); + + return $this->successResponse(); + } + + /** + * Display the specified resource. + */ + public function show(Expert $expert): JsonResponse + { + return $this->successResponse( + new ExpertManagementResource($expert) + ); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateRequest $request, Expert $expert): JsonResponse + { + $province = Province::query()->find($request->province_id); + $city = City::query()->find($request->city_id); + + $expert->update([ + 'username' => $request->username, + 'first_name' => $request->first_name, + 'last_name' => $request->last_name, + 'national_id' => $request->national_id, + 'password' => Hash::make($request->password), + 'email' => $request->email, + 'phone_number' => $request->phone_number, + 'province_id' => $request->province_id, + 'province_name' => $province->name, + 'city_id' => $request->city_id, + 'city_name' => $city->name, + ]); + + return $this->successResponse(); + } + + /** + * Remove the specified resource from storage. + * @throws Throwable + */ + public function destroy(Expert $expert): JsonResponse + { + DB::transaction(function () use ($expert) { + $expert->roles()->detach(); + $expert->permissions()->detach(); + $expert->delete(); + }); + + return $this->successResponse(); + } +} diff --git a/backend/app/Admin/Controllers/PermissionManagementController.php b/backend/app/Admin/Controllers/PermissionManagementController.php new file mode 100644 index 00000000..10462a70 --- /dev/null +++ b/backend/app/Admin/Controllers/PermissionManagementController.php @@ -0,0 +1,78 @@ +json( + DataTableFacade::run( + Permission::query(), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'] + ) + ); + } + + /** + * Store a newly created resource in storage. + */ + public function store(StoreRequest $request): JsonResponse + { + Permission::create([ + 'name' => $request->name, + 'guard_name' => 'web', + ]); + + return $this->successResponse(); + } + + /** + * Display the specified resource. + */ + public function show(Permission $permission): JsonResponse + { + return $this->successResponse($permission); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateRequest $request, Permission $permission): JsonResponse + { + $permission->update([ + 'name' => $request->name, + ]); + + return $this->successResponse(); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(Permission $permission): JsonResponse + { + $permission->delete(); + + return $this->successResponse(); + } +} diff --git a/backend/app/Admin/Controllers/RoleManagementController.php b/backend/app/Admin/Controllers/RoleManagementController.php new file mode 100755 index 00000000..c1dc1004 --- /dev/null +++ b/backend/app/Admin/Controllers/RoleManagementController.php @@ -0,0 +1,77 @@ +json($data); + } + + /** + * @throws Throwable + */ + public function store(StoreRequest $request): JsonResponse + { + DB::transaction(function () use ($request) { + $role = Role::create([ + 'name' => $request->name, + 'guard_name' => 'web', + ]); + + $role->givePermissionTo($request->permissions); + }); + + return $this->successResponse(); + } + + /** + * @throws Throwable + */ + public function update(UpdateRequest $request, Role $role): JsonResponse + { + DB::transaction(function () use ($request, $role) { + $role->update([ + 'name' => $request->name, + 'guard_name' => 'web', + ]); + + $role->syncPermissions($request->permissions); + }); + + return $this->successResponse(); + } + + public function show(Role $role): JsonResponse + { + return $this->successResponse($role); + } + + public function destroy(Role $role): JsonResponse + { + $role->delete(); + return $this->successResponse(); + } +} diff --git a/backend/app/Admin/Controllers/UserManagementController.php b/backend/app/Admin/Controllers/UserManagementController.php new file mode 100644 index 00000000..63e96da7 --- /dev/null +++ b/backend/app/Admin/Controllers/UserManagementController.php @@ -0,0 +1,113 @@ +json($data); + } + + /** + * Store a newly created resource in storage. + */ + public function store(StoreRequest $request): JsonResponse + { + $province = Province::query()->find($request->province_id); + $city = City::query()->find($request->city_id); + + User::query()->create([ + 'username' => $request->username, + 'first_name' => $request->first_name, + 'last_name' => $request->last_name, + 'national_id' => $request->national_id, + 'password' => Hash::make($request->password), + 'email' => $request->email, + 'birth_date' => $request->birth_date, + 'phone_number' => $request->phone_number, + 'postal_code' => $request->postal_code, + 'address' => $request->address, + 'province_id' => $request->province_id, + 'province_name' => $province->name, + 'city_id' => $request->city_id, + 'city_name' => $city->name, + ]); + + return $this->successResponse(); + } + + + /** + * Display the specified resource. + */ + public function show(User $user): JsonResponse + { + return $this->successResponse($user); + + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateRequest $request, User $user): JsonResponse + { + $province = Province::query()->find($request->province_id); + $city = City::query()->find($request->city_id); + + $user->update([ + 'first_name' => $request->first_name, + 'username' => $request->username, + 'last_name' => $request->last_name, + 'national_id' => $request->national_id, + 'password' => Hash::make($request->password), + 'email' => $request->email, + 'birth_date' => $request->birth_date, + 'phone_number' => $request->phone_number, + 'postal_code' => $request->postal_code, + 'address' => $request->address, + 'province_id' => $request->province_id, + 'province_name' => $province->name, + 'city_id' => $request->city_id, + 'city_name' => $city->name, + ]); + + return $this->successResponse(); + } + + /** + * Remove the specified resource from storage. + * @throws Throwable + */ + public function destroy(User $user): JsonResponse + { + $user->delete(); + + return $this->successResponse(); + } +} diff --git a/backend/app/Admin/Requests/ExpertManagement/StoreRequest.php b/backend/app/Admin/Requests/ExpertManagement/StoreRequest.php new file mode 100644 index 00000000..3a866cfe --- /dev/null +++ b/backend/app/Admin/Requests/ExpertManagement/StoreRequest.php @@ -0,0 +1,37 @@ + + */ + public function rules(): array + { + return [ + 'username' => 'required|string|max:255|unique:experts,username', + 'first_name' => 'required|string|max:255', + 'last_name' => 'required|string|max:255', + 'national_id' => 'required|string|max:20|unique:experts,national_id', + 'password' => 'required|string|min:8|confirmed', + 'email' => 'required|email|max:255|unique:experts,email', + 'phone_number' => 'required|string|max:20|unique:experts,phone_number', + 'province_id' => 'required|integer|exists:provinces,id', + 'city_id' => 'required|integer|exists:cities,id', + ]; + } +} diff --git a/backend/app/Admin/Requests/ExpertManagement/UpdateRequest.php b/backend/app/Admin/Requests/ExpertManagement/UpdateRequest.php new file mode 100644 index 00000000..f496445b --- /dev/null +++ b/backend/app/Admin/Requests/ExpertManagement/UpdateRequest.php @@ -0,0 +1,45 @@ + + */ + public function rules(): array + { + return [ + 'username' => ['string', 'max:255', + Rule::unique('experts', 'username')->ignore($this->expert->id),], + 'first_name' => 'string|max:255', + 'last_name' => 'string|max:255', + 'national_id' => ['string', 'max:20', + Rule::unique('experts', 'national_id')->ignore($this->expert->id),], + 'password' => 'string|min:8|confirmed', + 'email' => ['email', 'max:255', + Rule::unique('experts', 'email')->ignore($this->expert->id),], + 'phone_number' => ['string', 'max:20', + Rule::unique('experts', 'phone_number')->ignore($this->expert->id),], + 'province_id' => 'required|integer|exists:provinces,id', + 'city_id' => 'required|integer|exists:cities,id', + ]; + } +} diff --git a/backend/app/Admin/Requests/PermissionManagement/StoreRequest.php b/backend/app/Admin/Requests/PermissionManagement/StoreRequest.php new file mode 100644 index 00000000..7f91eda7 --- /dev/null +++ b/backend/app/Admin/Requests/PermissionManagement/StoreRequest.php @@ -0,0 +1,29 @@ + + */ + public function rules(): array + { + return [ + 'name' => 'required|string|unique:permissions,name', + ]; + } +} diff --git a/backend/app/Admin/Requests/PermissionManagement/UpdateRequest.php b/backend/app/Admin/Requests/PermissionManagement/UpdateRequest.php new file mode 100644 index 00000000..529ec458 --- /dev/null +++ b/backend/app/Admin/Requests/PermissionManagement/UpdateRequest.php @@ -0,0 +1,33 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255', Rule::unique('permission', 'name')->ignore($this->permission->id)], + ]; + } +} diff --git a/backend/app/Admin/Requests/RoleManagement/StoreRequest.php b/backend/app/Admin/Requests/RoleManagement/StoreRequest.php new file mode 100644 index 00000000..b30125a9 --- /dev/null +++ b/backend/app/Admin/Requests/RoleManagement/StoreRequest.php @@ -0,0 +1,31 @@ + + */ + public function rules(): array + { + return [ + 'name' => 'required|string|unique:roles,name', + 'permissions' => 'required|array', + 'permissions.*.name' => 'required|string|exists:permissions,name', + ]; + } +} diff --git a/backend/app/Admin/Requests/RoleManagement/UpdateRequest.php b/backend/app/Admin/Requests/RoleManagement/UpdateRequest.php new file mode 100644 index 00000000..4dd1cbf0 --- /dev/null +++ b/backend/app/Admin/Requests/RoleManagement/UpdateRequest.php @@ -0,0 +1,35 @@ + + */ + public function rules(): array + { + return [ + 'name' => ['required', 'string', 'max:255', Rule::unique('roles', 'name')->ignore($this->role->id)], + 'permissions' => 'required|array', + 'permissions.*.name' => 'required|string|exists:permissions,name', + ]; + } +} diff --git a/backend/app/Admin/Requests/UserManagement/StoreRequest.php b/backend/app/Admin/Requests/UserManagement/StoreRequest.php new file mode 100644 index 00000000..38208575 --- /dev/null +++ b/backend/app/Admin/Requests/UserManagement/StoreRequest.php @@ -0,0 +1,40 @@ + + */ + public function rules(): array + { + return [ + 'username' => 'required|string|max:255|unique:users,username', + 'first_name' => 'required|string|max:255', + 'last_name' => 'required|string|max:255', + 'national_id' => 'required|string|max:20|unique:users,national_id', + 'password' => 'required|string|min:6|confirmed', + 'email' => 'required|email|max:255|unique:users,email', + 'birth_date' => 'nullable|date', + 'phone_number' => 'required|string|max:20|unique:users,phone_number', + 'postal_code' => 'nullable|string|max:20', + 'address' => 'nullable|string|max:1000', + 'province_id' => 'required|integer|exists:provinces,id', + 'city_id' => 'required|integer|exists:cities,id', + ]; + } +} diff --git a/backend/app/Admin/Requests/UserManagement/UpdateRequest.php b/backend/app/Admin/Requests/UserManagement/UpdateRequest.php new file mode 100644 index 00000000..99c7af70 --- /dev/null +++ b/backend/app/Admin/Requests/UserManagement/UpdateRequest.php @@ -0,0 +1,49 @@ + + */ + public function rules(): array + { + + return [ + 'username' => ['string', 'max:255', + Rule::unique('users', 'username')->ignore($this->user->id),], + 'first_name' => 'string|max:255', + 'last_name' => 'string|max:255', + 'national_id' => ['string', 'max:20', + Rule::unique('users', 'national_id')->ignore($this->user->id),], + 'password' => 'string|min:8|confirmed', + 'email' => ['email', 'max:255', + Rule::unique('users', 'email')->ignore($this->user->id),], + 'birth_date' => 'nullable|date', + 'phone_number' => ['string', 'max:20', + Rule::unique('users', 'phone_number')->ignore($this->user->id),], + 'postal_code' => 'nullable|string|max:20', + 'address' => 'nullable|string|max:1000', + 'province_id' => 'integer|exists:provinces,id', + 'city_id' => 'integer|exists:cities,id', + ]; + } +} diff --git a/backend/app/Admin/Resources/ExpertManagementResource.php b/backend/app/Admin/Resources/ExpertManagementResource.php new file mode 100644 index 00000000..788c0c93 --- /dev/null +++ b/backend/app/Admin/Resources/ExpertManagementResource.php @@ -0,0 +1,41 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'username' => $this->username, + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, + 'national_id' => $this->national_id, + 'email' => $this->email, + 'phone_number' => $this->phone_number, + 'province_name' => $this->province_name, + 'city_name' => $this->city_name, + 'roles' => $this->roles() + ->pluck('name') + ->values(), + + 'permissions' => $this->getAllPermissions() + ->pluck('name') + ->values(), + ]; + } +} + diff --git a/backend/app/Models/Expert.php b/backend/app/Models/Expert.php index 214bb797..b55f8f55 100644 --- a/backend/app/Models/Expert.php +++ b/backend/app/Models/Expert.php @@ -6,6 +6,10 @@ use Database\Factories\ExpertFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * @method roles() + * @method permissions() + */ class Expert extends Model { /** @use HasFactory */ diff --git a/backend/app/Models/User.php b/backend/app/Models/User.php index 2d179582..ef9670d0 100755 --- a/backend/app/Models/User.php +++ b/backend/app/Models/User.php @@ -4,7 +4,6 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; use Database\Factories\UserFactory; -use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Attributes\Guarded; use Illuminate\Database\Eloquent\Attributes\Hidden; use Illuminate\Database\Eloquent\Factories\HasFactory; diff --git a/backend/app/User/Controllers/Dashboard/DocumentationController.php b/backend/app/User/Controllers/Dashboard/DocumentationController.php new file mode 100755 index 00000000..f62dd9ee --- /dev/null +++ b/backend/app/User/Controllers/Dashboard/DocumentationController.php @@ -0,0 +1,24 @@ + [ + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * Eloquent model should be used to retrieve your permissions. Of course, it + * is often just the "Permission" model but you may use whatever you like. + * + * The model you want to use as a Permission model needs to implement the + * `Spatie\Permission\Contracts\Permission` contract. + */ + + 'permission' => Permission::class, + + /* + * When using the "HasRoles" trait from this package, we need to know which + * Eloquent model should be used to retrieve your roles. Of course, it + * is often just the "Role" model but you may use whatever you like. + * + * The model you want to use as a Role model needs to implement the + * `Spatie\Permission\Contracts\Role` contract. + */ + + 'role' => Role::class, + + /* + * When using the "Teams" feature from this package, we need to know which + * Eloquent model should be used to retrieve your teams. Of course, it + * is often just the "Team" model but you may use whatever you like. + */ + 'team' => null, + + /* + * When using the "HasModels" trait and passing raw IDs to syncModels, + * attachModels, or detachModels, this model class will be used to + * resolve those IDs. If null, defaults to the guard's model. + */ + 'default_model' => null, + ], + + 'table_names' => [ + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'roles' => 'roles', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your permissions. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'permissions' => 'permissions', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your models permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_permissions' => 'model_has_permissions', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your models roles. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_roles' => 'model_has_roles', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'role_has_permissions' => 'role_has_permissions', + ], + + 'column_names' => [ + /* + * Change this if you want to name the related pivots other than defaults + */ + 'role_pivot_key' => null, // default 'role_id', + 'permission_pivot_key' => null, // default 'permission_id', + + /* + * Change this if you want to name the related model primary key other than + * `model_id`. + * + * For example, this would be nice if your primary keys are all UUIDs. In + * that case, name this `model_uuid`. + */ + + 'model_morph_key' => 'model_id', + + /* + * Change this if you want to use the teams feature and your related model's + * foreign key is other than `team_id`. + */ + + 'team_foreign_key' => 'team_id', + ], + + /* + * When set to true, the method for checking permissions will be registered on the gate. + * Set this to false if you want to implement custom logic for checking permissions. + */ + + 'register_permission_check_method' => true, + + /* + * When set to true, Laravel\Octane\Events\OperationTerminated event listener will be registered + * this will refresh permissions on every TickTerminated, TaskTerminated and RequestTerminated + * NOTE: This should not be needed in most cases, but an Octane/Vapor combination benefited from it. + */ + 'register_octane_reset_listener' => false, + + /* + * Events will fire when a role or permission is assigned/unassigned: + * \Spatie\Permission\Events\RoleAttachedEvent + * \Spatie\Permission\Events\RoleDetachedEvent + * \Spatie\Permission\Events\PermissionAttachedEvent + * \Spatie\Permission\Events\PermissionDetachedEvent + * + * To enable, set to true, and then create listeners to watch these events. + */ + 'events_enabled' => false, + + /* + * Teams Feature. + * When set to true the package implements teams using the 'team_foreign_key'. + * If you want the migrations to register the 'team_foreign_key', you must + * set this to true before doing the migration. + * If you already did the migration then you must make a new migration to also + * add 'team_foreign_key' to 'roles', 'model_has_roles', and 'model_has_permissions' + * (view the latest version of this package's migration file) + */ + + 'teams' => false, + + /* + * The class to use to resolve the permissions team id + */ + 'team_resolver' => DefaultTeamResolver::class, + + /* + * Passport Client Credentials Grant + * When set to true the package will use Passports Client to check permissions + */ + + 'use_passport_client_credentials' => false, + + /* + * When set to true, the required permission names are added to exception messages. + * This could be considered an information leak in some contexts, so the default + * setting is false here for optimum safety. + */ + + 'display_permission_in_exception' => false, + + /* + * When set to true, the required role names are added to exception messages. + * This could be considered an information leak in some contexts, so the default + * setting is false here for optimum safety. + */ + + 'display_role_in_exception' => false, + + /* + * By default wildcard permission lookups are disabled. + * See documentation to understand supported syntax. + */ + + 'enable_wildcard_permission' => false, + + /* + * The class to use for interpreting wildcard permissions. + * If you need to modify delimiters, override the class and specify its name here. + */ + // 'wildcard_permission' => Spatie\Permission\WildcardPermission::class, + + /* Cache-specific settings */ + + 'cache' => [ + + /* + * By default all permissions are cached for 24 hours to speed up performance. + * When permissions or roles are updated the cache is flushed automatically. + */ + + 'expiration_time' => DateInterval::createFromDateString('24 hours'), + + /* + * The cache key used to store all permissions. + */ + + 'key' => 'spatie.permission.cache', + + /* + * You may optionally indicate a specific cache driver to use for permission and + * role caching using any of the `store` drivers listed in the cache.php config + * file. Using 'default' here means to use the `default` set in cache.php. + */ + + 'store' => 'default', + ], +]; diff --git a/backend/database/migrations/2026_05_10_123913_create_permission_tables.php b/backend/database/migrations/2026_05_10_123913_create_permission_tables.php new file mode 100644 index 00000000..89862751 --- /dev/null +++ b/backend/database/migrations/2026_05_10_123913_create_permission_tables.php @@ -0,0 +1,137 @@ +id(); // permission id + $table->string('name'); + $table->string('guard_name'); + $table->timestamps(); + + $table->unique(['name', 'guard_name']); + }); + + /** + * See `docs/prerequisites.md` for suggested lengths on 'name' and 'guard_name' if "1071 Specified key was too long" errors are encountered. + */ + Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) { + $table->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'); + $table->string('guard_name'); + $table->timestamps(); + if ($teams || config('permission.testing')) { + $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); + } else { + $table->unique(['name', 'guard_name']); + } + }); + + Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) { + $table->unsignedBigInteger($pivotPermission); + + $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->foreign($pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->cascadeOnDelete(); + 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'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } else { + $table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } + }); + + Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) { + $table->unsignedBigInteger($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'); + + $table->foreign($pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->cascadeOnDelete(); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); + + $table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } else { + $table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } + }); + + Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) { + $table->unsignedBigInteger($pivotPermission); + $table->unsignedBigInteger($pivotRole); + + $table->foreign($pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->cascadeOnDelete(); + + $table->foreign($pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->cascadeOnDelete(); + + $table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary'); + }); + + app('cache') + ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) + ->forget(config('permission.cache.key')); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + $tableNames = config('permission.table_names'); + + throw_if(empty($tableNames), '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::dropIfExists($tableNames['role_has_permissions']); + Schema::dropIfExists($tableNames['model_has_roles']); + Schema::dropIfExists($tableNames['model_has_permissions']); + Schema::dropIfExists($tableNames['roles']); + Schema::dropIfExists($tableNames['permissions']); + } +}; diff --git a/backend/routes/web.php b/backend/routes/web.php index fc6836d2..b81845c1 100755 --- a/backend/routes/web.php +++ b/backend/routes/web.php @@ -1,5 +1,9 @@ name('edit'); Route::post('change_password', 'changePassword')->name('changePassword'); }); + +Route::prefix('admin') + ->name('Admin.') + ->group(function () { + Route::prefix('user_management') + ->name('user_management.') + ->controller(UserManagementController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::post('/', 'store')->name('store'); + Route::get('/{user}', 'show')->name('show'); + Route::post('/{user}', 'update')->name('update'); + Route::delete('/{user}', 'destroy')->name('destroy'); + }); + Route::prefix('roles') + ->name('roles.') + ->controller(RoleManagementController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::post('/', 'store')->name('store'); + Route::get('/{role}', 'show')->name('show'); + Route::post('/{role}', 'update')->name('update'); + Route::delete('/{role}', 'destroy')->name('destroy'); + }); + Route::prefix('permissions') + ->name('permissions.') + ->controller(PermissionManagementController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::post('/', 'store')->name('store'); + Route::get('/{permission}', 'show')->name('show'); + Route::post('/{permission}', 'update')->name('update'); + Route::delete('/{permission}', 'destroy')->name('destroy'); + }); + Route::prefix('expert') + ->name('expert.') + ->controller(ExpertManagementController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::post('/', 'store')->name('store'); + Route::get('/{expert}', 'show')->name('show'); + Route::post('/{expert}', 'update')->name('update'); + Route::delete('/{expert}', 'destroy')->name('destroy'); + }); + }); +