From 80d7089c2d0c0c5af83b6889879b565e1aa4b307 Mon Sep 17 00:00:00 2001 From: Ibrahim Isleem Date: Tue, 26 Nov 2024 23:02:07 +0200 Subject: [PATCH 1/2] Added Migrations, Sanctum package, created controllers, custome request rules and authentication --- app/Http/Controllers/AttachmentController.php | 69 +++ app/Http/Controllers/AuthController.php | 59 +++ .../Controllers/BeneficiaryController.php | 69 +++ app/Http/Controllers/LogController.php | 69 +++ app/Http/Controllers/PermissionController.php | 69 +++ .../ProposalBeneficiaryController.php | 69 +++ app/Http/Controllers/ProposalController.php | 69 +++ .../Controllers/ProposalDetailController.php | 69 +++ app/Http/Controllers/RoleController.php | 69 +++ .../Controllers/RolePermissionController.php | 69 +++ app/Http/Controllers/UnitController.php | 69 +++ app/Http/Controllers/UserController.php | 69 +++ .../Controllers/WarehouseDetailController.php | 69 +++ app/Http/Requests/StoreAttachmentRequest.php | 35 ++ app/Http/Requests/StoreBeneficiaryRequest.php | 35 ++ app/Http/Requests/StoreLogRequest.php | 34 ++ app/Http/Requests/StorePermissionRequest.php | 30 ++ .../StoreProposalBeneficiaryRequest.php | 33 ++ .../Requests/StoreProposalDetailRequest.php | 33 ++ app/Http/Requests/StoreProposalRequest.php | 34 ++ .../Requests/StoreRolePermissionRequest.php | 31 ++ app/Http/Requests/StoreRoleRequest.php | 30 ++ app/Http/Requests/StoreUnitRequest.php | 32 ++ app/Http/Requests/StoreUserRequest.php | 38 ++ app/Http/Requests/StoreUserRoleRequest.php | 3 +- .../Requests/StoreWarehouseDetailRequest.php | 32 ++ app/Http/Requests/StoreWarehouseRequest.php | 4 +- app/Http/Requests/UpdateAttachmentRequest.php | 30 ++ .../Requests/UpdateBeneficiaryRequest.php | 30 ++ app/Http/Requests/UpdateLogRequest.php | 30 ++ app/Http/Requests/UpdatePermissionRequest.php | 30 ++ .../UpdateProposalBeneficiaryRequest.php | 30 ++ .../Requests/UpdateProposalDetailRequest.php | 30 ++ app/Http/Requests/UpdateProposalRequest.php | 30 ++ .../Requests/UpdateRolePermissionRequest.php | 30 ++ app/Http/Requests/UpdateRoleRequest.php | 30 ++ app/Http/Requests/UpdateUnitRequest.php | 30 ++ app/Http/Requests/UpdateUserRequest.php | 30 ++ .../Requests/UpdateWarehouseDetailRequest.php | 30 ++ app/Http/Resources/AttachmentResource.php | 19 + app/Http/Resources/BeneficiaryResource.php | 19 + app/Http/Resources/DashboardResource.php | 19 + app/Http/Resources/LogResource.php | 19 + app/Http/Resources/PermissionResource.php | 19 + app/Http/Resources/ProfileResource.php | 19 + .../Resources/ProposalBeneficiaryResource.php | 19 + app/Http/Resources/ProposalDetailResource.php | 19 + app/Http/Resources/ProposalResource.php | 19 + app/Http/Resources/RegisterResource.php | 19 + app/Http/Resources/RolePermissionResource.php | 19 + app/Http/Resources/RoleResource.php | 19 + app/Http/Resources/SessionsResource.php | 19 + app/Http/Resources/UnitResource.php | 19 + app/Http/Resources/UserResource.php | 19 + app/Http/Resources/UserRoleResource.php | 19 + .../Resources/WarehouseDetailResource.php | 19 + app/Http/Resources/WarehouseResource.php | 19 + app/Models/User.php | 41 +- app/Models2/Attachment.php | 11 + app/Models2/Beneficiary.php | 11 + app/Models2/Log.php | 11 + app/Models2/Permission.php | 11 + app/Models2/Proposal.php | 11 + app/Models2/ProposalBeneficiary.php | 11 + app/Models2/ProposalDetail.php | 11 + app/Models2/Role.php | 11 + app/Models2/RolePermission.php | 11 + app/Models2/Unit.php | 11 + app/Models2/User2.php | 48 ++ app/Models2/UserRole.php | 11 + app/Models2/Warehouse.php | 11 + app/Models2/WarehouseDetail.php | 11 + app/Policies/AttachmentPolicy.php | 94 ++++ app/Policies/BeneficiaryPolicy.php | 94 ++++ app/Policies/LogPolicy.php | 94 ++++ app/Policies/PermissionPolicy.php | 94 ++++ app/Policies/ProposalBeneficiaryPolicy.php | 94 ++++ app/Policies/ProposalDetailPolicy.php | 94 ++++ app/Policies/ProposalPolicy.php | 94 ++++ app/Policies/RolePermissionPolicy.php | 94 ++++ app/Policies/RolePolicy.php | 94 ++++ app/Policies/UnitPolicy.php | 94 ++++ app/Policies/UserPolicy.php | 93 ++++ app/Policies/WarehouseDetailPolicy.php | 94 ++++ composer.json | 1 + composer.lock | 425 ++++++++++-------- config/sanctum.php | 83 ++++ createModels.py | 2 +- createResource.py | 2 +- .../0001_01_01_000000_create_users_table.php | 13 +- ...4_11_26_185446_create_user_roles_table.php | 35 ++ .../2024_11_26_185451_create_roles_table.php | 31 ++ ..._11_26_185456_create_permissions_table.php | 31 ++ ...6_185502_create_role_permissions_table.php | 35 ++ .../2024_11_26_185508_create_units_table.php | 33 ++ ...4_11_26_185515_create_warehouses_table.php | 33 ++ ..._185519_create_warehouse_details_table.php | 36 ++ ...1_26_185525_create_beneficiaries_table.php | 36 ++ ...24_11_26_185530_create_proposals_table.php | 37 ++ ...6_185537_create_proposal_details_table.php | 37 ++ ...42_create_proposal_beneficiaries_table.php | 37 ++ ..._11_26_185548_create_attachments_table.php | 36 ++ .../2024_11_26_185554_create_logs_table.php | 36 ++ ...01_create_personal_access_tokens_table.php | 33 ++ database/seeders/AttachmentSeeder.php | 18 + database/seeders/BeneficiarySeeder.php | 18 + database/seeders/LogSeeder.php | 18 + database/seeders/PermissionSeeder.php | 18 + .../seeders/ProposalBeneficiarySeeder.php | 18 + database/seeders/ProposalDetailSeeder.php | 18 + database/seeders/ProposalSeeder.php | 18 + database/seeders/RolePermissionSeeder.php | 18 + database/seeders/RoleSeeder.php | 18 + database/seeders/UnitSeeder.php | 18 + database/seeders/UserSeeder.php | 18 + database/seeders/WarehouseDetailSeeder.php | 18 + routes/web.php | 15 +- stubs/migration.create.stub | 4 +- stubs/migration.stub | 4 +- 119 files changed, 4379 insertions(+), 224 deletions(-) create mode 100644 app/Http/Controllers/AttachmentController.php create mode 100644 app/Http/Controllers/AuthController.php create mode 100644 app/Http/Controllers/BeneficiaryController.php create mode 100644 app/Http/Controllers/LogController.php create mode 100644 app/Http/Controllers/PermissionController.php create mode 100644 app/Http/Controllers/ProposalBeneficiaryController.php create mode 100644 app/Http/Controllers/ProposalController.php create mode 100644 app/Http/Controllers/ProposalDetailController.php create mode 100644 app/Http/Controllers/RoleController.php create mode 100644 app/Http/Controllers/RolePermissionController.php create mode 100644 app/Http/Controllers/UnitController.php create mode 100644 app/Http/Controllers/UserController.php create mode 100644 app/Http/Controllers/WarehouseDetailController.php create mode 100644 app/Http/Requests/StoreAttachmentRequest.php create mode 100644 app/Http/Requests/StoreBeneficiaryRequest.php create mode 100644 app/Http/Requests/StoreLogRequest.php create mode 100644 app/Http/Requests/StorePermissionRequest.php create mode 100644 app/Http/Requests/StoreProposalBeneficiaryRequest.php create mode 100644 app/Http/Requests/StoreProposalDetailRequest.php create mode 100644 app/Http/Requests/StoreProposalRequest.php create mode 100644 app/Http/Requests/StoreRolePermissionRequest.php create mode 100644 app/Http/Requests/StoreRoleRequest.php create mode 100644 app/Http/Requests/StoreUnitRequest.php create mode 100644 app/Http/Requests/StoreUserRequest.php create mode 100644 app/Http/Requests/StoreWarehouseDetailRequest.php create mode 100644 app/Http/Requests/UpdateAttachmentRequest.php create mode 100644 app/Http/Requests/UpdateBeneficiaryRequest.php create mode 100644 app/Http/Requests/UpdateLogRequest.php create mode 100644 app/Http/Requests/UpdatePermissionRequest.php create mode 100644 app/Http/Requests/UpdateProposalBeneficiaryRequest.php create mode 100644 app/Http/Requests/UpdateProposalDetailRequest.php create mode 100644 app/Http/Requests/UpdateProposalRequest.php create mode 100644 app/Http/Requests/UpdateRolePermissionRequest.php create mode 100644 app/Http/Requests/UpdateRoleRequest.php create mode 100644 app/Http/Requests/UpdateUnitRequest.php create mode 100644 app/Http/Requests/UpdateUserRequest.php create mode 100644 app/Http/Requests/UpdateWarehouseDetailRequest.php create mode 100644 app/Http/Resources/AttachmentResource.php create mode 100644 app/Http/Resources/BeneficiaryResource.php create mode 100644 app/Http/Resources/DashboardResource.php create mode 100644 app/Http/Resources/LogResource.php create mode 100644 app/Http/Resources/PermissionResource.php create mode 100644 app/Http/Resources/ProfileResource.php create mode 100644 app/Http/Resources/ProposalBeneficiaryResource.php create mode 100644 app/Http/Resources/ProposalDetailResource.php create mode 100644 app/Http/Resources/ProposalResource.php create mode 100644 app/Http/Resources/RegisterResource.php create mode 100644 app/Http/Resources/RolePermissionResource.php create mode 100644 app/Http/Resources/RoleResource.php create mode 100644 app/Http/Resources/SessionsResource.php create mode 100644 app/Http/Resources/UnitResource.php create mode 100644 app/Http/Resources/UserResource.php create mode 100644 app/Http/Resources/UserRoleResource.php create mode 100644 app/Http/Resources/WarehouseDetailResource.php create mode 100644 app/Http/Resources/WarehouseResource.php create mode 100644 app/Models2/Attachment.php create mode 100644 app/Models2/Beneficiary.php create mode 100644 app/Models2/Log.php create mode 100644 app/Models2/Permission.php create mode 100644 app/Models2/Proposal.php create mode 100644 app/Models2/ProposalBeneficiary.php create mode 100644 app/Models2/ProposalDetail.php create mode 100644 app/Models2/Role.php create mode 100644 app/Models2/RolePermission.php create mode 100644 app/Models2/Unit.php create mode 100644 app/Models2/User2.php create mode 100644 app/Models2/UserRole.php create mode 100644 app/Models2/Warehouse.php create mode 100644 app/Models2/WarehouseDetail.php create mode 100644 app/Policies/AttachmentPolicy.php create mode 100644 app/Policies/BeneficiaryPolicy.php create mode 100644 app/Policies/LogPolicy.php create mode 100644 app/Policies/PermissionPolicy.php create mode 100644 app/Policies/ProposalBeneficiaryPolicy.php create mode 100644 app/Policies/ProposalDetailPolicy.php create mode 100644 app/Policies/ProposalPolicy.php create mode 100644 app/Policies/RolePermissionPolicy.php create mode 100644 app/Policies/RolePolicy.php create mode 100644 app/Policies/UnitPolicy.php create mode 100644 app/Policies/UserPolicy.php create mode 100644 app/Policies/WarehouseDetailPolicy.php create mode 100644 config/sanctum.php create mode 100644 database/migrations/2024_11_26_185446_create_user_roles_table.php create mode 100644 database/migrations/2024_11_26_185451_create_roles_table.php create mode 100644 database/migrations/2024_11_26_185456_create_permissions_table.php create mode 100644 database/migrations/2024_11_26_185502_create_role_permissions_table.php create mode 100644 database/migrations/2024_11_26_185508_create_units_table.php create mode 100644 database/migrations/2024_11_26_185515_create_warehouses_table.php create mode 100644 database/migrations/2024_11_26_185519_create_warehouse_details_table.php create mode 100644 database/migrations/2024_11_26_185525_create_beneficiaries_table.php create mode 100644 database/migrations/2024_11_26_185530_create_proposals_table.php create mode 100644 database/migrations/2024_11_26_185537_create_proposal_details_table.php create mode 100644 database/migrations/2024_11_26_185542_create_proposal_beneficiaries_table.php create mode 100644 database/migrations/2024_11_26_185548_create_attachments_table.php create mode 100644 database/migrations/2024_11_26_185554_create_logs_table.php create mode 100644 database/migrations/2024_11_26_202901_create_personal_access_tokens_table.php create mode 100644 database/seeders/AttachmentSeeder.php create mode 100644 database/seeders/BeneficiarySeeder.php create mode 100644 database/seeders/LogSeeder.php create mode 100644 database/seeders/PermissionSeeder.php create mode 100644 database/seeders/ProposalBeneficiarySeeder.php create mode 100644 database/seeders/ProposalDetailSeeder.php create mode 100644 database/seeders/ProposalSeeder.php create mode 100644 database/seeders/RolePermissionSeeder.php create mode 100644 database/seeders/RoleSeeder.php create mode 100644 database/seeders/UnitSeeder.php create mode 100644 database/seeders/UserSeeder.php create mode 100644 database/seeders/WarehouseDetailSeeder.php diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php new file mode 100644 index 0000000..e005d4f --- /dev/null +++ b/app/Http/Controllers/AttachmentController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',Attachment::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),Attachment::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $attachment = Attachment::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $attachment->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new AttachmentResource($attachment); + } + public function show(Request $request,Attachment $attachment) + { + if(!$this->user->is_permitted_to('view',Attachment::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new AttachmentResource($attachment); + } + public function update(Request $request, Attachment $attachment) + { + if(!$this->user->is_permitted_to('update',Attachment::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),Attachment::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $attachment->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $attachment->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new AttachmentResource($attachment); + } + public function destroy(Request $request,Attachment $attachment) + { + if(!$this->user->is_permitted_to('delete',Attachment::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $attachment->delete(); + + return new AttachmentResource($attachment); + } +} diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php new file mode 100644 index 0000000..dd67bd6 --- /dev/null +++ b/app/Http/Controllers/AuthController.php @@ -0,0 +1,59 @@ +validate([ + 'name' => 'required|string|max:255', + 'email' => 'required|email|unique:users,email', + 'password' => 'required|min:6|confirmed', + ]); + + $user = User::create([ + 'name' => $request->name, + 'email' => $request->email, + 'password' => Hash::make($request->password), + ]); + + return response()->json([ + 'message' => 'User registered successfully!', + 'user' => $user, + ], 201); + } + + public function login(Request $request) + { + $request->validate([ + 'email' => 'required|email', + 'password' => 'required' + ]); + + if (Auth::attempt($request->only('email', 'password'))) { + $request->session()->regenerate(); + return response()->json(['message' => 'Logged in successfully!'], 200); + } + + return response()->json(['message' => 'Invalid credentials'], 401); + } + + public function logout(Request $request) + { + Auth::guard('web')->logout(); + $request->session()->invalidate(); + $request->session()->regenerateToken(); + return response()->json(['message' => 'Logged out successfully!'], 200); + } + + public function profile() + { + return response()->json(Auth::user()); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/BeneficiaryController.php b/app/Http/Controllers/BeneficiaryController.php new file mode 100644 index 0000000..a73c37f --- /dev/null +++ b/app/Http/Controllers/BeneficiaryController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',Beneficiary::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),Beneficiary::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $beneficiary = Beneficiary::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $beneficiary->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new BeneficiaryResource($beneficiary); + } + public function show(Request $request,Beneficiary $beneficiary) + { + if(!$this->user->is_permitted_to('view',Beneficiary::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new BeneficiaryResource($beneficiary); + } + public function update(Request $request, Beneficiary $beneficiary) + { + if(!$this->user->is_permitted_to('update',Beneficiary::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),Beneficiary::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $beneficiary->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $beneficiary->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new BeneficiaryResource($beneficiary); + } + public function destroy(Request $request,Beneficiary $beneficiary) + { + if(!$this->user->is_permitted_to('delete',Beneficiary::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $beneficiary->delete(); + + return new BeneficiaryResource($beneficiary); + } +} diff --git a/app/Http/Controllers/LogController.php b/app/Http/Controllers/LogController.php new file mode 100644 index 0000000..de1a874 --- /dev/null +++ b/app/Http/Controllers/LogController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',Log::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),Log::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $log = Log::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $log->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new LogResource($log); + } + public function show(Request $request,Log $log) + { + if(!$this->user->is_permitted_to('view',Log::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new LogResource($log); + } + public function update(Request $request, Log $log) + { + if(!$this->user->is_permitted_to('update',Log::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),Log::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $log->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $log->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new LogResource($log); + } + public function destroy(Request $request,Log $log) + { + if(!$this->user->is_permitted_to('delete',Log::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $log->delete(); + + return new LogResource($log); + } +} diff --git a/app/Http/Controllers/PermissionController.php b/app/Http/Controllers/PermissionController.php new file mode 100644 index 0000000..1f41105 --- /dev/null +++ b/app/Http/Controllers/PermissionController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',Permission::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),Permission::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $permission = Permission::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $permission->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new PermissionResource($permission); + } + public function show(Request $request,Permission $permission) + { + if(!$this->user->is_permitted_to('view',Permission::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new PermissionResource($permission); + } + public function update(Request $request, Permission $permission) + { + if(!$this->user->is_permitted_to('update',Permission::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),Permission::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $permission->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $permission->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new PermissionResource($permission); + } + public function destroy(Request $request,Permission $permission) + { + if(!$this->user->is_permitted_to('delete',Permission::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $permission->delete(); + + return new PermissionResource($permission); + } +} diff --git a/app/Http/Controllers/ProposalBeneficiaryController.php b/app/Http/Controllers/ProposalBeneficiaryController.php new file mode 100644 index 0000000..cc663ba --- /dev/null +++ b/app/Http/Controllers/ProposalBeneficiaryController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',ProposalBeneficiary::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),ProposalBeneficiary::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $proposalBeneficiary = ProposalBeneficiary::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $proposalBeneficiary->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new ProposalBeneficiaryResource($proposalBeneficiary); + } + public function show(Request $request,ProposalBeneficiary $proposalBeneficiary) + { + if(!$this->user->is_permitted_to('view',ProposalBeneficiary::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new ProposalBeneficiaryResource($proposalBeneficiary); + } + public function update(Request $request, ProposalBeneficiary $proposalBeneficiary) + { + if(!$this->user->is_permitted_to('update',ProposalBeneficiary::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),ProposalBeneficiary::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $proposalBeneficiary->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $proposalBeneficiary->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new ProposalBeneficiaryResource($proposalBeneficiary); + } + public function destroy(Request $request,ProposalBeneficiary $proposalBeneficiary) + { + if(!$this->user->is_permitted_to('delete',ProposalBeneficiary::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $proposalBeneficiary->delete(); + + return new ProposalBeneficiaryResource($proposalBeneficiary); + } +} diff --git a/app/Http/Controllers/ProposalController.php b/app/Http/Controllers/ProposalController.php new file mode 100644 index 0000000..0f6cf44 --- /dev/null +++ b/app/Http/Controllers/ProposalController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',Proposal::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),Proposal::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $proposal = Proposal::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $proposal->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new ProposalResource($proposal); + } + public function show(Request $request,Proposal $proposal) + { + if(!$this->user->is_permitted_to('view',Proposal::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new ProposalResource($proposal); + } + public function update(Request $request, Proposal $proposal) + { + if(!$this->user->is_permitted_to('update',Proposal::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),Proposal::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $proposal->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $proposal->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new ProposalResource($proposal); + } + public function destroy(Request $request,Proposal $proposal) + { + if(!$this->user->is_permitted_to('delete',Proposal::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $proposal->delete(); + + return new ProposalResource($proposal); + } +} diff --git a/app/Http/Controllers/ProposalDetailController.php b/app/Http/Controllers/ProposalDetailController.php new file mode 100644 index 0000000..516d9d1 --- /dev/null +++ b/app/Http/Controllers/ProposalDetailController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',ProposalDetail::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),ProposalDetail::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $proposalDetail = ProposalDetail::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $proposalDetail->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new ProposalDetailResource($proposalDetail); + } + public function show(Request $request,ProposalDetail $proposalDetail) + { + if(!$this->user->is_permitted_to('view',ProposalDetail::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new ProposalDetailResource($proposalDetail); + } + public function update(Request $request, ProposalDetail $proposalDetail) + { + if(!$this->user->is_permitted_to('update',ProposalDetail::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),ProposalDetail::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $proposalDetail->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $proposalDetail->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new ProposalDetailResource($proposalDetail); + } + public function destroy(Request $request,ProposalDetail $proposalDetail) + { + if(!$this->user->is_permitted_to('delete',ProposalDetail::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $proposalDetail->delete(); + + return new ProposalDetailResource($proposalDetail); + } +} diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php new file mode 100644 index 0000000..e7d3650 --- /dev/null +++ b/app/Http/Controllers/RoleController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',Role::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),Role::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $role = Role::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $role->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new RoleResource($role); + } + public function show(Request $request,Role $role) + { + if(!$this->user->is_permitted_to('view',Role::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new RoleResource($role); + } + public function update(Request $request, Role $role) + { + if(!$this->user->is_permitted_to('update',Role::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),Role::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $role->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $role->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new RoleResource($role); + } + public function destroy(Request $request,Role $role) + { + if(!$this->user->is_permitted_to('delete',Role::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $role->delete(); + + return new RoleResource($role); + } +} diff --git a/app/Http/Controllers/RolePermissionController.php b/app/Http/Controllers/RolePermissionController.php new file mode 100644 index 0000000..1282eac --- /dev/null +++ b/app/Http/Controllers/RolePermissionController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',RolePermission::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),RolePermission::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $rolePermission = RolePermission::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $rolePermission->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new RolePermissionResource($rolePermission); + } + public function show(Request $request,RolePermission $rolePermission) + { + if(!$this->user->is_permitted_to('view',RolePermission::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new RolePermissionResource($rolePermission); + } + public function update(Request $request, RolePermission $rolePermission) + { + if(!$this->user->is_permitted_to('update',RolePermission::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),RolePermission::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $rolePermission->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $rolePermission->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new RolePermissionResource($rolePermission); + } + public function destroy(Request $request,RolePermission $rolePermission) + { + if(!$this->user->is_permitted_to('delete',RolePermission::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $rolePermission->delete(); + + return new RolePermissionResource($rolePermission); + } +} diff --git a/app/Http/Controllers/UnitController.php b/app/Http/Controllers/UnitController.php new file mode 100644 index 0000000..04cbeca --- /dev/null +++ b/app/Http/Controllers/UnitController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',Unit::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),Unit::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $unit = Unit::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $unit->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new UnitResource($unit); + } + public function show(Request $request,Unit $unit) + { + if(!$this->user->is_permitted_to('view',Unit::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new UnitResource($unit); + } + public function update(Request $request, Unit $unit) + { + if(!$this->user->is_permitted_to('update',Unit::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),Unit::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $unit->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $unit->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new UnitResource($unit); + } + public function destroy(Request $request,Unit $unit) + { + if(!$this->user->is_permitted_to('delete',Unit::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $unit->delete(); + + return new UnitResource($unit); + } +} diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100644 index 0000000..1e8fbf7 --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',User::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),User::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $user = User::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $user->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new UserResource($user); + } + public function show(Request $request,User $user) + { + if(!$this->user->is_permitted_to('view',User::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new UserResource($user); + } + public function update(Request $request, User $user) + { + if(!$this->user->is_permitted_to('update',User::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),User::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $user->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $user->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new UserResource($user); + } + public function destroy(Request $request,User $user) + { + if(!$this->user->is_permitted_to('delete',User::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $user->delete(); + + return new UserResource($user); + } +} diff --git a/app/Http/Controllers/WarehouseDetailController.php b/app/Http/Controllers/WarehouseDetailController.php new file mode 100644 index 0000000..5ccad4e --- /dev/null +++ b/app/Http/Controllers/WarehouseDetailController.php @@ -0,0 +1,69 @@ +sort($request)->paginate((request('per_page')??request('itemsPerPage'))??15)); + } + public function store(Request $request) + { + if(!$this->user->is_permitted_to('store',WarehouseDetail::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + + $validator = Validator::make($request->all(),WarehouseDetail::createRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $warehouseDetail = WarehouseDetail::create($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $warehouseDetail->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new WarehouseDetailResource($warehouseDetail); + } + public function show(Request $request,WarehouseDetail $warehouseDetail) + { + if(!$this->user->is_permitted_to('view',WarehouseDetail::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + return new WarehouseDetailResource($warehouseDetail); + } + public function update(Request $request, WarehouseDetail $warehouseDetail) + { + if(!$this->user->is_permitted_to('update',WarehouseDetail::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $validator = Validator::make($request->all(),WarehouseDetail::updateRules($this->user)); + if($validator->fails()){ + return response()->json(['errors'=>$validator->errors()],422); + } + $warehouseDetail->update($validator->validated()); + if ($request->translations) { + foreach ($request->translations as $translation) + $warehouseDetail->setTranslation($translation['field'], $translation['locale'], $translation['value'])->save(); + } + return new WarehouseDetailResource($warehouseDetail); + } + public function destroy(Request $request,WarehouseDetail $warehouseDetail) + { + if(!$this->user->is_permitted_to('delete',WarehouseDetail::class,$request)) + return response()->json(['message'=>'not_permitted'],422); + $warehouseDetail->delete(); + + return new WarehouseDetailResource($warehouseDetail); + } +} diff --git a/app/Http/Requests/StoreAttachmentRequest.php b/app/Http/Requests/StoreAttachmentRequest.php new file mode 100644 index 0000000..6e484ce --- /dev/null +++ b/app/Http/Requests/StoreAttachmentRequest.php @@ -0,0 +1,35 @@ + 'required|integer', + 'record_id' => 'required|integer', + 'filename' => 'required|string|max:255', + 'path' => 'required|string', + 'file_extension' => 'required|string|max:10', + 'filesize' => 'required|integer|min:0', + ]; + } +} diff --git a/app/Http/Requests/StoreBeneficiaryRequest.php b/app/Http/Requests/StoreBeneficiaryRequest.php new file mode 100644 index 0000000..a3f107f --- /dev/null +++ b/app/Http/Requests/StoreBeneficiaryRequest.php @@ -0,0 +1,35 @@ + 'required|string|max:255', + 'national_id' => 'required|string|max:20|unique:beneficiaries,national_id', + 'phone' => 'required|string|max:20', + 'email' => 'nullable|email|max:255', + 'dob' => 'nullable|date', + 'father_id' => 'nullable|string|max:255', + ]; + } +} diff --git a/app/Http/Requests/StoreLogRequest.php b/app/Http/Requests/StoreLogRequest.php new file mode 100644 index 0000000..7a354f1 --- /dev/null +++ b/app/Http/Requests/StoreLogRequest.php @@ -0,0 +1,34 @@ + 'required|string|max:255', + 'record_id' => 'required|integer', + 'type' => 'required|string|max:255', + 'notes' => 'nullable|string', + 'user_id' => 'required|exists:users,id', + ]; + } +} diff --git a/app/Http/Requests/StorePermissionRequest.php b/app/Http/Requests/StorePermissionRequest.php new file mode 100644 index 0000000..55cb83c --- /dev/null +++ b/app/Http/Requests/StorePermissionRequest.php @@ -0,0 +1,30 @@ + 'required|string|max:255|unique:permissions,name', + ]; + } +} diff --git a/app/Http/Requests/StoreProposalBeneficiaryRequest.php b/app/Http/Requests/StoreProposalBeneficiaryRequest.php new file mode 100644 index 0000000..3dc1aac --- /dev/null +++ b/app/Http/Requests/StoreProposalBeneficiaryRequest.php @@ -0,0 +1,33 @@ + 'required|exists:proposals,id', + 'beneficiary_id' => 'required|exists:beneficiaries,id', + 'status' => 'required|string|in:received,granted', + 'notes' => 'nullable|string', + ]; + } +} diff --git a/app/Http/Requests/StoreProposalDetailRequest.php b/app/Http/Requests/StoreProposalDetailRequest.php new file mode 100644 index 0000000..8031064 --- /dev/null +++ b/app/Http/Requests/StoreProposalDetailRequest.php @@ -0,0 +1,33 @@ + 'required|exists:proposals,id', + 'unit_id' => 'required|exists:units,id', + 'value' => 'required|numeric|min:0', + 'notes' => 'nullable|string', + ]; + } +} diff --git a/app/Http/Requests/StoreProposalRequest.php b/app/Http/Requests/StoreProposalRequest.php new file mode 100644 index 0000000..9bb7324 --- /dev/null +++ b/app/Http/Requests/StoreProposalRequest.php @@ -0,0 +1,34 @@ + 'required|exists:users,id', + 'title' => 'required|string|max:255', + 'body' => 'required|string', + 'status' => 'required|in:accepted,unaccepted,pending,preparing,done', + 'notes' => 'nullable|string', + ]; + } +} diff --git a/app/Http/Requests/StoreRolePermissionRequest.php b/app/Http/Requests/StoreRolePermissionRequest.php new file mode 100644 index 0000000..db659a6 --- /dev/null +++ b/app/Http/Requests/StoreRolePermissionRequest.php @@ -0,0 +1,31 @@ + 'required|exists:roles,id', + 'permission_id' => 'required|exists:permissions,id', + ]; + } +} diff --git a/app/Http/Requests/StoreRoleRequest.php b/app/Http/Requests/StoreRoleRequest.php new file mode 100644 index 0000000..cb7c354 --- /dev/null +++ b/app/Http/Requests/StoreRoleRequest.php @@ -0,0 +1,30 @@ + 'required|string|max:255|unique:roles,name', + ]; + } +} diff --git a/app/Http/Requests/StoreUnitRequest.php b/app/Http/Requests/StoreUnitRequest.php new file mode 100644 index 0000000..1178695 --- /dev/null +++ b/app/Http/Requests/StoreUnitRequest.php @@ -0,0 +1,32 @@ + 'required|string|max:255', + 'description' => 'nullable|string', + 'estimated_price' => 'required|numeric|min:0', + ]; + } +} diff --git a/app/Http/Requests/StoreUserRequest.php b/app/Http/Requests/StoreUserRequest.php new file mode 100644 index 0000000..46480e9 --- /dev/null +++ b/app/Http/Requests/StoreUserRequest.php @@ -0,0 +1,38 @@ + 'required|string|max:255', + 'status' => 'required|string|max:255', + 'name' => 'required|string|max:255', + 'email' => 'required|email|unique:users,email', + 'phone' => 'required|string|max:20', + 'password' => 'required|string|min:8', + 'position_id' => 'nullable|exists:positions,id', + 'is_active' => 'boolean', + 'job_title' => 'required|string|max:255', + ]; + } +} diff --git a/app/Http/Requests/StoreUserRoleRequest.php b/app/Http/Requests/StoreUserRoleRequest.php index aded383..3c28f03 100644 --- a/app/Http/Requests/StoreUserRoleRequest.php +++ b/app/Http/Requests/StoreUserRoleRequest.php @@ -24,7 +24,8 @@ public function authorize() public function rules() { return [ - // + 'user_id' => 'required|exists:users,id', + 'role_id' => 'required|exists:roles,id', ]; } } diff --git a/app/Http/Requests/StoreWarehouseDetailRequest.php b/app/Http/Requests/StoreWarehouseDetailRequest.php new file mode 100644 index 0000000..4c6d6be --- /dev/null +++ b/app/Http/Requests/StoreWarehouseDetailRequest.php @@ -0,0 +1,32 @@ + 'required|exists:warehouses,id', + 'unit_id' => 'required|exists:units,id', + 'amount' => 'required|integer|min:0', + ]; + } +} diff --git a/app/Http/Requests/StoreWarehouseRequest.php b/app/Http/Requests/StoreWarehouseRequest.php index ae545a1..5321669 100644 --- a/app/Http/Requests/StoreWarehouseRequest.php +++ b/app/Http/Requests/StoreWarehouseRequest.php @@ -24,7 +24,9 @@ public function authorize() public function rules() { return [ - // + 'bio' => 'nullable|string', + 'status' => 'required|in:open,close,full,not_available', + 'location' => 'required|string|max:255', ]; } } diff --git a/app/Http/Requests/UpdateAttachmentRequest.php b/app/Http/Requests/UpdateAttachmentRequest.php new file mode 100644 index 0000000..44cbc76 --- /dev/null +++ b/app/Http/Requests/UpdateAttachmentRequest.php @@ -0,0 +1,30 @@ + */ - use HasFactory, Notifiable; + use HasApiTokens, HasFactory; - /** - * The attributes that are mass assignable. - * - * @var array - */ - protected $fillable = [ - 'name', - 'email', - 'password', - ]; - - /** - * The attributes that should be hidden for serialization. - * - * @var array - */ protected $hidden = [ 'password', 'remember_token', ]; - /** - * Get the attributes that should be cast. - * - * @return array - */ - protected function casts(): array - { - return [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', - ]; - } + protected $casts = [ + 'email_verified_at' => 'datetime', + ]; + + protected $guarded = []; + } diff --git a/app/Models2/Attachment.php b/app/Models2/Attachment.php new file mode 100644 index 0000000..dc04c23 --- /dev/null +++ b/app/Models2/Attachment.php @@ -0,0 +1,11 @@ + */ + use HasFactory, Notifiable; + + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'name', + 'email', + 'password', + ]; + + /** + * The attributes that should be hidden for serialization. + * + * @var array + */ + protected $hidden = [ + 'password', + 'remember_token', + ]; + + /** + * Get the attributes that should be cast. + * + * @return array + */ + protected function casts(): array + { + return [ + 'email_verified_at' => 'datetime', + 'password' => 'hashed', + ]; + } +} diff --git a/app/Models2/UserRole.php b/app/Models2/UserRole.php new file mode 100644 index 0000000..f067f50 --- /dev/null +++ b/app/Models2/UserRole.php @@ -0,0 +1,11 @@ +=7.0,<7.1.5" }, "require-dev": { "doctrine/dbal": "^3.6|^4", "predis/predis": "^1.1|^2.0", - "symfony/cache": "^6.4|^7.0", + "symfony/cache": "^6.4.12|^7.1.5", "symfony/dependency-injection": "^6.4|^7.0", "symfony/expression-language": "^6.4|^7.0", "symfony/http-kernel": "^6.4|^7.0", @@ -3769,7 +3839,7 @@ "description": "Defines an object-oriented layer for the HTTP specification", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-foundation/tree/v7.1.6" + "source": "https://github.com/symfony/http-foundation/tree/v7.1.8" }, "funding": [ { @@ -3785,20 +3855,20 @@ "type": "tidelift" } ], - "time": "2024-10-11T19:23:14+00:00" + "time": "2024-11-09T09:16:45+00:00" }, { "name": "symfony/http-kernel", - "version": "v7.1.6", + "version": "v7.1.8", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "5d8315899cd76b2e7e29179bf5fea103e41bdf03" + "reference": "33fef24e3dc79d6d30bf4936531f2f4bd2ca189e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/5d8315899cd76b2e7e29179bf5fea103e41bdf03", - "reference": "5d8315899cd76b2e7e29179bf5fea103e41bdf03", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/33fef24e3dc79d6d30bf4936531f2f4bd2ca189e", + "reference": "33fef24e3dc79d6d30bf4936531f2f4bd2ca189e", "shasum": "" }, "require": { @@ -3883,7 +3953,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v7.1.6" + "source": "https://github.com/symfony/http-kernel/tree/v7.1.8" }, "funding": [ { @@ -3899,7 +3969,7 @@ "type": "tidelift" } ], - "time": "2024-10-27T13:54:21+00:00" + "time": "2024-11-13T14:25:32+00:00" }, { "name": "symfony/mailer", @@ -4703,16 +4773,16 @@ }, { "name": "symfony/process", - "version": "v7.1.6", + "version": "v7.1.8", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "6aaa189ddb4ff6b5de8fa3210f2fb42c87b4d12e" + "reference": "42783370fda6e538771f7c7a36e9fa2ee3a84892" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/6aaa189ddb4ff6b5de8fa3210f2fb42c87b4d12e", - "reference": "6aaa189ddb4ff6b5de8fa3210f2fb42c87b4d12e", + "url": "https://api.github.com/repos/symfony/process/zipball/42783370fda6e538771f7c7a36e9fa2ee3a84892", + "reference": "42783370fda6e538771f7c7a36e9fa2ee3a84892", "shasum": "" }, "require": { @@ -4744,7 +4814,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.1.6" + "source": "https://github.com/symfony/process/tree/v7.1.8" }, "funding": [ { @@ -4760,7 +4830,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2024-11-06T14:23:19+00:00" }, { "name": "symfony/routing", @@ -4928,16 +4998,16 @@ }, { "name": "symfony/string", - "version": "v7.1.6", + "version": "v7.1.8", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "61b72d66bf96c360a727ae6232df5ac83c71f626" + "reference": "591ebd41565f356fcd8b090fe64dbb5878f50281" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/61b72d66bf96c360a727ae6232df5ac83c71f626", - "reference": "61b72d66bf96c360a727ae6232df5ac83c71f626", + "url": "https://api.github.com/repos/symfony/string/zipball/591ebd41565f356fcd8b090fe64dbb5878f50281", + "reference": "591ebd41565f356fcd8b090fe64dbb5878f50281", "shasum": "" }, "require": { @@ -4995,7 +5065,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.6" + "source": "https://github.com/symfony/string/tree/v7.1.8" }, "funding": [ { @@ -5011,7 +5081,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2024-11-13T13:31:21+00:00" }, { "name": "symfony/translation", @@ -5261,16 +5331,16 @@ }, { "name": "symfony/var-dumper", - "version": "v7.1.6", + "version": "v7.1.8", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "cb5bd55a6b8c2c1c7fb68b0aeae0e257948a720c" + "reference": "7bb01a47b1b00428d32b5e7b4d3b2d1aa58d3db8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/cb5bd55a6b8c2c1c7fb68b0aeae0e257948a720c", - "reference": "cb5bd55a6b8c2c1c7fb68b0aeae0e257948a720c", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/7bb01a47b1b00428d32b5e7b4d3b2d1aa58d3db8", + "reference": "7bb01a47b1b00428d32b5e7b4d3b2d1aa58d3db8", "shasum": "" }, "require": { @@ -5324,7 +5394,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v7.1.6" + "source": "https://github.com/symfony/var-dumper/tree/v7.1.8" }, "funding": [ { @@ -5340,7 +5410,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2024-11-08T15:46:42+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", @@ -5481,16 +5551,16 @@ }, { "name": "voku/portable-ascii", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/voku/portable-ascii.git", - "reference": "b56450eed252f6801410d810c8e1727224ae0743" + "reference": "b1d923f88091c6bf09699efcd7c8a1b1bfd7351d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/voku/portable-ascii/zipball/b56450eed252f6801410d810c8e1727224ae0743", - "reference": "b56450eed252f6801410d810c8e1727224ae0743", + "url": "https://api.github.com/repos/voku/portable-ascii/zipball/b1d923f88091c6bf09699efcd7c8a1b1bfd7351d", + "reference": "b1d923f88091c6bf09699efcd7c8a1b1bfd7351d", "shasum": "" }, "require": { @@ -5515,7 +5585,7 @@ "authors": [ { "name": "Lars Moelleken", - "homepage": "http://www.moelleken.org/" + "homepage": "https://www.moelleken.org/" } ], "description": "Portable ASCII library - performance optimized (ascii) string functions for php.", @@ -5527,7 +5597,7 @@ ], "support": { "issues": "https://github.com/voku/portable-ascii/issues", - "source": "https://github.com/voku/portable-ascii/tree/2.0.1" + "source": "https://github.com/voku/portable-ascii/tree/2.0.3" }, "funding": [ { @@ -5551,7 +5621,7 @@ "type": "tidelift" } ], - "time": "2022-03-08T17:03:00+00:00" + "time": "2024-11-21T01:49:47+00:00" }, { "name": "webmozart/assert", @@ -5615,16 +5685,16 @@ "packages-dev": [ { "name": "fakerphp/faker", - "version": "v1.23.1", + "version": "v1.24.1", "source": { "type": "git", "url": "https://github.com/FakerPHP/Faker.git", - "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b" + "reference": "e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/bfb4fe148adbf78eff521199619b93a52ae3554b", - "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5", + "reference": "e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5", "shasum": "" }, "require": { @@ -5672,9 +5742,9 @@ ], "support": { "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.23.1" + "source": "https://github.com/FakerPHP/Faker/tree/v1.24.1" }, - "time": "2024-01-02T13:46:09+00:00" + "time": "2024-11-21T13:46:39+00:00" }, { "name": "filp/whoops", @@ -5800,16 +5870,16 @@ }, { "name": "laravel/pail", - "version": "v1.2.0", + "version": "v1.2.1", "source": { "type": "git", "url": "https://github.com/laravel/pail.git", - "reference": "085a2306b520c3896afa361c25704e5fa3c27bf0" + "reference": "353ac12134b98e2e7c3333d916bd3e523931e583" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pail/zipball/085a2306b520c3896afa361c25704e5fa3c27bf0", - "reference": "085a2306b520c3896afa361c25704e5fa3c27bf0", + "url": "https://api.github.com/repos/laravel/pail/zipball/353ac12134b98e2e7c3333d916bd3e523931e583", + "reference": "353ac12134b98e2e7c3333d916bd3e523931e583", "shasum": "" }, "require": { @@ -5824,8 +5894,9 @@ "symfony/console": "^6.0|^7.0" }, "require-dev": { + "laravel/framework": "^10.24|^11.0", "laravel/pint": "^1.13", - "orchestra/testbench": "^8.12|^9.0", + "orchestra/testbench-core": "^8.12|^9.0", "pestphp/pest": "^2.20", "pestphp/pest-plugin-type-coverage": "^2.3", "phpstan/phpstan": "^1.10", @@ -5873,20 +5944,20 @@ "issues": "https://github.com/laravel/pail/issues", "source": "https://github.com/laravel/pail" }, - "time": "2024-10-21T13:59:30+00:00" + "time": "2024-10-23T12:56:23+00:00" }, { "name": "laravel/pint", - "version": "v1.18.1", + "version": "v1.18.3", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "35c00c05ec43e6b46d295efc0f4386ceb30d50d9" + "reference": "cef51821608239040ab841ad6e1c6ae502ae3026" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/35c00c05ec43e6b46d295efc0f4386ceb30d50d9", - "reference": "35c00c05ec43e6b46d295efc0f4386ceb30d50d9", + "url": "https://api.github.com/repos/laravel/pint/zipball/cef51821608239040ab841ad6e1c6ae502ae3026", + "reference": "cef51821608239040ab841ad6e1c6ae502ae3026", "shasum": "" }, "require": { @@ -5897,13 +5968,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.64.0", - "illuminate/view": "^10.48.20", - "larastan/larastan": "^2.9.8", + "friendsofphp/php-cs-fixer": "^3.65.0", + "illuminate/view": "^10.48.24", + "larastan/larastan": "^2.9.11", "laravel-zero/framework": "^10.4.0", "mockery/mockery": "^1.6.12", - "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.35.1" + "nunomaduro/termwind": "^1.17.0", + "pestphp/pest": "^2.36.0" }, "bin": [ "builds/pint" @@ -5939,20 +6010,20 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-09-24T17:22:50+00:00" + "time": "2024-11-26T15:34:00+00:00" }, { "name": "laravel/sail", - "version": "v1.37.1", + "version": "v1.39.0", "source": { "type": "git", "url": "https://github.com/laravel/sail.git", - "reference": "7efa151ea0d16f48233d6a6cd69f81270acc6e93" + "reference": "be9d67a11133535811f9ec4ab5c176a2f47250fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/sail/zipball/7efa151ea0d16f48233d6a6cd69f81270acc6e93", - "reference": "7efa151ea0d16f48233d6a6cd69f81270acc6e93", + "url": "https://api.github.com/repos/laravel/sail/zipball/be9d67a11133535811f9ec4ab5c176a2f47250fc", + "reference": "be9d67a11133535811f9ec4ab5c176a2f47250fc", "shasum": "" }, "require": { @@ -6002,7 +6073,7 @@ "issues": "https://github.com/laravel/sail/issues", "source": "https://github.com/laravel/sail" }, - "time": "2024-10-29T20:18:14+00:00" + "time": "2024-11-25T23:48:26+00:00" }, { "name": "mockery/mockery", @@ -6089,16 +6160,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.12.0", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/123267b2c49fbf30d78a7b2d333f6be754b94845", + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845", "shasum": "" }, "require": { @@ -6137,7 +6208,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.1" }, "funding": [ { @@ -6145,7 +6216,7 @@ "type": "tidelift" } ], - "time": "2024-06-12T14:39:25+00:00" + "time": "2024-11-08T17:47:46+00:00" }, { "name": "nunomaduro/collision", diff --git a/config/sanctum.php b/config/sanctum.php new file mode 100644 index 0000000..764a82f --- /dev/null +++ b/config/sanctum.php @@ -0,0 +1,83 @@ + explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( + '%s%s', + 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', + Sanctum::currentApplicationUrlWithPort() + ))), + + /* + |-------------------------------------------------------------------------- + | Sanctum Guards + |-------------------------------------------------------------------------- + | + | This array contains the authentication guards that will be checked when + | Sanctum is trying to authenticate a request. If none of these guards + | are able to authenticate the request, Sanctum will use the bearer + | token that's present on an incoming request for authentication. + | + */ + + 'guard' => ['web'], + + /* + |-------------------------------------------------------------------------- + | Expiration Minutes + |-------------------------------------------------------------------------- + | + | This value controls the number of minutes until an issued token will be + | considered expired. This will override any values set in the token's + | "expires_at" attribute, but first-party sessions are not affected. + | + */ + + 'expiration' => null, + + /* + |-------------------------------------------------------------------------- + | Token Prefix + |-------------------------------------------------------------------------- + | + | Sanctum can prefix new tokens in order to take advantage of numerous + | security scanning initiatives maintained by open source platforms + | that notify developers if they commit tokens into repositories. + | + | See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning + | + */ + + 'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''), + + /* + |-------------------------------------------------------------------------- + | Sanctum Middleware + |-------------------------------------------------------------------------- + | + | When authenticating your first-party SPA with Sanctum you may need to + | customize some of the middleware Sanctum uses while processing the + | request. You may change the middleware listed below as required. + | + */ + + 'middleware' => [ + 'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class, + 'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class, + 'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class, + ], + +]; diff --git a/createModels.py b/createModels.py index 0a87ba4..52b3fdc 100644 --- a/createModels.py +++ b/createModels.py @@ -20,5 +20,5 @@ for model in models: print('Creating Model for: ',model) - system('php artisan make:model '+model+' -a --api') + system(f'docker exec -t php php artisan make:model {model} -a --api') print('Done.') \ No newline at end of file diff --git a/createResource.py b/createResource.py index cb8fd46..636d699 100644 --- a/createResource.py +++ b/createResource.py @@ -8,5 +8,5 @@ if path.exists(resources_path + file + 'Resource.php'): print(file+'Resource' + 'already exists.. skip') continue - system('php artisan make:resource '+file+'Resource') + system(f'docker exec -t php php artisan make:resource '+file+'Resource') print('Finish.') \ No newline at end of file diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 05fb5d9..413403c 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_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. */ @@ -13,12 +12,20 @@ public function up(): void { Schema::create('users', function (Blueprint $table) { $table->id(); + $table->string('type'); + $table->string('status'); $table->string('name'); $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); + $table->string('phone'); $table->string('password'); + $table->unsignedBigInteger('position_id')->nullable(); + $table->boolean('is_active')->default(true); + $table->string('job_title'); $table->rememberToken(); + $table->timestamps(); + + $table->foreign('position_id')->references('id')->on('positions')->nullOnDelete(); }); Schema::create('password_reset_tokens', function (Blueprint $table) { diff --git a/database/migrations/2024_11_26_185446_create_user_roles_table.php b/database/migrations/2024_11_26_185446_create_user_roles_table.php new file mode 100644 index 0000000..3ec8fc4 --- /dev/null +++ b/database/migrations/2024_11_26_185446_create_user_roles_table.php @@ -0,0 +1,35 @@ +id(); + $table->unsignedBigInteger('user_id'); + $table->unsignedBigInteger('role_id'); + $table->timestamps(); + + $table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete(); + $table->foreign('role_id')->references('id')->on('roles')->cascadeOnDelete(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('user_roles'); + } +}; diff --git a/database/migrations/2024_11_26_185451_create_roles_table.php b/database/migrations/2024_11_26_185451_create_roles_table.php new file mode 100644 index 0000000..2521e57 --- /dev/null +++ b/database/migrations/2024_11_26_185451_create_roles_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('roles'); + } +}; diff --git a/database/migrations/2024_11_26_185456_create_permissions_table.php b/database/migrations/2024_11_26_185456_create_permissions_table.php new file mode 100644 index 0000000..dcaa6da --- /dev/null +++ b/database/migrations/2024_11_26_185456_create_permissions_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name')->unique(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('permissions'); + } +}; diff --git a/database/migrations/2024_11_26_185502_create_role_permissions_table.php b/database/migrations/2024_11_26_185502_create_role_permissions_table.php new file mode 100644 index 0000000..dbd9b47 --- /dev/null +++ b/database/migrations/2024_11_26_185502_create_role_permissions_table.php @@ -0,0 +1,35 @@ +id(); + $table->unsignedBigInteger('role_id'); + $table->unsignedBigInteger('permission_id'); + $table->timestamps(); + + $table->foreign('role_id')->references('id')->on('roles')->cascadeOnDelete(); + $table->foreign('permission_id')->references('id')->on('permissions')->cascadeOnDelete(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('role_permissions'); + } +}; diff --git a/database/migrations/2024_11_26_185508_create_units_table.php b/database/migrations/2024_11_26_185508_create_units_table.php new file mode 100644 index 0000000..7b935d2 --- /dev/null +++ b/database/migrations/2024_11_26_185508_create_units_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('name'); + $table->text('description')->nullable(); + $table->decimal('estimated_price', 10, 2)->default(0); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('units'); + } +}; diff --git a/database/migrations/2024_11_26_185515_create_warehouses_table.php b/database/migrations/2024_11_26_185515_create_warehouses_table.php new file mode 100644 index 0000000..a5210b8 --- /dev/null +++ b/database/migrations/2024_11_26_185515_create_warehouses_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('bio')->nullable(); + $table->string('status'); + $table->string('location'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('warehouses'); + } +}; diff --git a/database/migrations/2024_11_26_185519_create_warehouse_details_table.php b/database/migrations/2024_11_26_185519_create_warehouse_details_table.php new file mode 100644 index 0000000..1d6db5d --- /dev/null +++ b/database/migrations/2024_11_26_185519_create_warehouse_details_table.php @@ -0,0 +1,36 @@ +id(); + $table->unsignedBigInteger('warehouse_id'); + $table->unsignedBigInteger('unit_id'); + $table->integer('amount'); + $table->timestamps(); + + $table->foreign('warehouse_id')->references('id')->on('warehouses')->onDelete('cascade'); + $table->foreign('unit_id')->references('id')->on('units')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('warehouse_details'); + } +}; diff --git a/database/migrations/2024_11_26_185525_create_beneficiaries_table.php b/database/migrations/2024_11_26_185525_create_beneficiaries_table.php new file mode 100644 index 0000000..365ec97 --- /dev/null +++ b/database/migrations/2024_11_26_185525_create_beneficiaries_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('name'); + $table->string('national_id')->unique(); + $table->string('phone'); + $table->string('email')->nullable(); + $table->date('dob')->nullable(); + $table->string('father_id')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('beneficiaries'); + } +}; diff --git a/database/migrations/2024_11_26_185530_create_proposals_table.php b/database/migrations/2024_11_26_185530_create_proposals_table.php new file mode 100644 index 0000000..319c277 --- /dev/null +++ b/database/migrations/2024_11_26_185530_create_proposals_table.php @@ -0,0 +1,37 @@ +id(); + $table->unsignedBigInteger('donor_id'); + $table->string('title'); + $table->text('body'); + $table->enum('status', ['accepted', 'unaccepted', 'pending', 'preparing', 'done'])->default('pending'); + $table->text('notes')->nullable(); + $table->timestamps(); + + $table->foreign('donor_id')->references('id')->on('users')->cascadeOnDelete(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('proposals'); + } +}; diff --git a/database/migrations/2024_11_26_185537_create_proposal_details_table.php b/database/migrations/2024_11_26_185537_create_proposal_details_table.php new file mode 100644 index 0000000..089ef35 --- /dev/null +++ b/database/migrations/2024_11_26_185537_create_proposal_details_table.php @@ -0,0 +1,37 @@ +id(); + $table->unsignedBigInteger('proposal_id'); + $table->unsignedBigInteger('unit_id'); + $table->decimal('value', 10, 2)->default(0); + $table->text('notes')->nullable(); + $table->timestamps(); + + $table->foreign('proposal_id')->references('id')->on('proposals')->cascadeOnDelete(); + $table->foreign('unit_id')->references('id')->on('units')->cascadeOnDelete(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('proposal_details'); + } +}; diff --git a/database/migrations/2024_11_26_185542_create_proposal_beneficiaries_table.php b/database/migrations/2024_11_26_185542_create_proposal_beneficiaries_table.php new file mode 100644 index 0000000..f82e7d6 --- /dev/null +++ b/database/migrations/2024_11_26_185542_create_proposal_beneficiaries_table.php @@ -0,0 +1,37 @@ +id(); + $table->unsignedBigInteger('proposal_id'); + $table->unsignedBigInteger('beneficiary_id'); + $table->string('status'); + $table->text('notes')->nullable(); + $table->timestamps(); + + $table->foreign('proposal_id')->references('id')->on('proposals')->onDelete('cascade'); + $table->foreign('beneficiary_id')->references('id')->on('beneficiaries')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('proposal_beneficiaries'); + } +}; diff --git a/database/migrations/2024_11_26_185548_create_attachments_table.php b/database/migrations/2024_11_26_185548_create_attachments_table.php new file mode 100644 index 0000000..f35bc95 --- /dev/null +++ b/database/migrations/2024_11_26_185548_create_attachments_table.php @@ -0,0 +1,36 @@ +id(); + $table->unsignedBigInteger('entity_id'); + $table->unsignedBigInteger('record_id'); + $table->string('filename'); + $table->string('path'); + $table->string('file_extension', 10); + $table->integer('filesize'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('attachments'); + } +}; diff --git a/database/migrations/2024_11_26_185554_create_logs_table.php b/database/migrations/2024_11_26_185554_create_logs_table.php new file mode 100644 index 0000000..64d5711 --- /dev/null +++ b/database/migrations/2024_11_26_185554_create_logs_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('entity_id'); + $table->unsignedBigInteger('record_id'); + $table->string('type'); + $table->text('notes')->nullable(); + $table->unsignedBigInteger('user_id'); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('logs'); + } +}; diff --git a/database/migrations/2024_11_26_202901_create_personal_access_tokens_table.php b/database/migrations/2024_11_26_202901_create_personal_access_tokens_table.php new file mode 100644 index 0000000..e828ad8 --- /dev/null +++ b/database/migrations/2024_11_26_202901_create_personal_access_tokens_table.php @@ -0,0 +1,33 @@ +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(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('personal_access_tokens'); + } +}; diff --git a/database/seeders/AttachmentSeeder.php b/database/seeders/AttachmentSeeder.php new file mode 100644 index 0000000..bf76fcf --- /dev/null +++ b/database/seeders/AttachmentSeeder.php @@ -0,0 +1,18 @@ +name('profile'); Route::get('/static-sign-in/', [DashboardController::class, 'index'])->name('static-sign-in'); Route::get('/static-sign-up/', [DashboardController::class, 'index'])->name('static-sign-up'); -Route::get('/logout/', [DashboardController::class, 'index'])->name('logout'); -Route::get('/login/', [DashboardController::class, 'index'])->name('login'); -Route::get('/register/', [DashboardController::class, 'index'])->name('register'); -Route::get('/user-profile/', [ProfileController::class, 'index'])->name('user-profile'); +// Route::get('/logout/', [DashboardController::class, 'index'])->name('logout'); +// Route::get('/login/', [DashboardController::class, 'index'])->name('login'); +// Route::get('/register/', [DashboardController::class, 'index'])->name('register'); +// Route::get('/user-profile/', [ProfileController::class, 'index'])->name('user-profile'); Route::get('/user-management/', [ProfileController::class, 'index'])->name('user-management'); + + +Route::post('/register', [AuthController::class, 'register']); +Route::post('/login', [AuthController::class, 'login']); +Route::post('/logout', [AuthController::class, 'logout']); +Route::get('/profile', [AuthController::class, 'profile'])->middleware('auth:web'); diff --git a/stubs/migration.create.stub b/stubs/migration.create.stub index f4a56a0..0e0ec22 100644 --- a/stubs/migration.create.stub +++ b/stubs/migration.create.stub @@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class {{ class }} extends Migration +return new class extends Migration { /** * Run the migrations. @@ -28,4 +28,4 @@ class {{ class }} extends Migration { Schema::dropIfExists('{{ table }}'); } -} +}; diff --git a/stubs/migration.stub b/stubs/migration.stub index fd0e437..41dd1c8 100644 --- a/stubs/migration.stub +++ b/stubs/migration.stub @@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class {{ class }} extends Migration +return new class extends Migration { /** * Run the migrations. @@ -25,4 +25,4 @@ class {{ class }} extends Migration { // } -} +}; From 3c334d91c649fa2072c5293937403603b525aa5d Mon Sep 17 00:00:00 2001 From: Ibrahim Isleem Date: Thu, 28 Nov 2024 16:10:21 +0200 Subject: [PATCH 2/2] Added Routes, BaseModel --- app/Http/Controllers/Controller.php | 9 ++++- app/Models/Attachment.php | 4 ++- app/Models/BaseModel.php | 33 +++++++++++++++++ app/Models/Beneficiary.php | 4 ++- app/Models/Log.php | 4 ++- app/Models/Permission.php | 3 +- app/Models/Proposal.php | 3 +- app/Models/ProposalBeneficiary.php | 3 +- app/Models/ProposalDetail.php | 3 +- app/Models/Role.php | 3 +- app/Models/RolePermission.php | 3 +- app/Models/Unit.php | 3 +- app/Models/User.php | 36 +++++++++++++++++++ app/Models/UserRole.php | 3 +- app/Models/Warehouse.php | 3 +- app/Models/WarehouseDetail.php | 3 +- ..._11_26_185548_create_attachments_table.php | 1 + routes/web.php | 34 +++++++++++++++--- 18 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 app/Models/BaseModel.php diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 8677cd5..e5278e1 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -1,8 +1,15 @@ user()) + $this->user = auth('web')->user(); + } } diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index dc04c23..36f8765 100644 --- a/app/Models/Attachment.php +++ b/app/Models/Attachment.php @@ -5,7 +5,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Attachment extends Model +class Attachment extends BaseModel { use HasFactory; + + public static $controllable = true; } diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php new file mode 100644 index 0000000..aad2d09 --- /dev/null +++ b/app/Models/BaseModel.php @@ -0,0 +1,33 @@ +getTable(); + } + public function scopeSearch($query, $request) + { + } + public function scopeSort($query, $request) + { + } + + public function files() + { + return $this->morphMany(Attachment::class, 'entity_id')->where('user_id', '=', auth('web')->user()->id); + } +} diff --git a/app/Models/Beneficiary.php b/app/Models/Beneficiary.php index 12274bf..41ca8bc 100644 --- a/app/Models/Beneficiary.php +++ b/app/Models/Beneficiary.php @@ -5,7 +5,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Beneficiary extends Model +class Beneficiary extends BaseModel { use HasFactory; + + public static $controllable = true; } diff --git a/app/Models/Log.php b/app/Models/Log.php index 5e42929..fa1a3a6 100644 --- a/app/Models/Log.php +++ b/app/Models/Log.php @@ -5,7 +5,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Log extends Model +class Log extends BaseModel { use HasFactory; + + public static $controllable = true; } diff --git a/app/Models/Permission.php b/app/Models/Permission.php index 40d4034..c1a73ee 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Permission extends Model +class Permission extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index 9601f74..eb69682 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Proposal extends Model +class Proposal extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/app/Models/ProposalBeneficiary.php b/app/Models/ProposalBeneficiary.php index 9334bd1..e0789f4 100644 --- a/app/Models/ProposalBeneficiary.php +++ b/app/Models/ProposalBeneficiary.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class ProposalBeneficiary extends Model +class ProposalBeneficiary extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/app/Models/ProposalDetail.php b/app/Models/ProposalDetail.php index 4a163b6..abd8c2c 100644 --- a/app/Models/ProposalDetail.php +++ b/app/Models/ProposalDetail.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class ProposalDetail extends Model +class ProposalDetail extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/app/Models/Role.php b/app/Models/Role.php index 42bb4d2..458ec9b 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Role extends Model +class Role extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/app/Models/RolePermission.php b/app/Models/RolePermission.php index 4f83881..02fcd48 100644 --- a/app/Models/RolePermission.php +++ b/app/Models/RolePermission.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class RolePermission extends Model +class RolePermission extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/app/Models/Unit.php b/app/Models/Unit.php index 110beb0..6ee57ce 100644 --- a/app/Models/Unit.php +++ b/app/Models/Unit.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Unit extends Model +class Unit extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/app/Models/User.php b/app/Models/User.php index b6f249a..833ab49 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,10 +6,12 @@ use Illuminate\Database\Eloquent\Model; use Laravel\Sanctum\HasApiTokens; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Support\Facades\Route; class User extends Authenticatable { use HasApiTokens, HasFactory; + public static $controllable = true; protected $hidden = [ 'password', @@ -22,4 +24,38 @@ class User extends Authenticatable protected $guarded = []; + public function is_permitted_to($name, $class_name, $request) + { + $permitted = true; + if (!$this->current_role) + return true; + if (isset($class_name::$controllable)) { + if (isset($class_name::$field_to_check)) { + $model = null; + $field = $class_name::$field_to_check; + $params = Route::current()->parameters(); + $model = reset($params); + if ($request->id) { + $model = $class_name::find($request->id); + } + if (!$model) { + if (!$request->$field) + return false; + $p_name = $class_name::getSubName($request->$field); + } else { + $p_name = $class_name::getSubName($model->$field); + } + } else { + return true; + } + + $permission = $this->current_role->permissions()->where('code', '=', $p_name)->first(); + if (!$permission) + return true; + $p = $name; + return $permission->$p; + } + return true; + } + } diff --git a/app/Models/UserRole.php b/app/Models/UserRole.php index f067f50..bdc2883 100644 --- a/app/Models/UserRole.php +++ b/app/Models/UserRole.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class UserRole extends Model +class UserRole extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/app/Models/Warehouse.php b/app/Models/Warehouse.php index 0571f31..234d870 100644 --- a/app/Models/Warehouse.php +++ b/app/Models/Warehouse.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Warehouse extends Model +class Warehouse extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/app/Models/WarehouseDetail.php b/app/Models/WarehouseDetail.php index 8709b8c..d2255f0 100644 --- a/app/Models/WarehouseDetail.php +++ b/app/Models/WarehouseDetail.php @@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class WarehouseDetail extends Model +class WarehouseDetail extends BaseModel { use HasFactory; + public static $controllable = true; } diff --git a/database/migrations/2024_11_26_185548_create_attachments_table.php b/database/migrations/2024_11_26_185548_create_attachments_table.php index f35bc95..ebf9e7e 100644 --- a/database/migrations/2024_11_26_185548_create_attachments_table.php +++ b/database/migrations/2024_11_26_185548_create_attachments_table.php @@ -16,6 +16,7 @@ public function up() $table->id(); $table->unsignedBigInteger('entity_id'); $table->unsignedBigInteger('record_id'); + $table->unsignedBigInteger('user_id'); $table->string('filename'); $table->string('path'); $table->string('file_extension', 10); diff --git a/routes/web.php b/routes/web.php index e035d51..e607d94 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,7 +25,33 @@ Route::get('/user-management/', [ProfileController::class, 'index'])->name('user-management'); -Route::post('/register', [AuthController::class, 'register']); -Route::post('/login', [AuthController::class, 'login']); -Route::post('/logout', [AuthController::class, 'logout']); -Route::get('/profile', [AuthController::class, 'profile'])->middleware('auth:web'); +// Route::post('/register', [AuthController::class, 'register']); +// Route::post('/login', [AuthController::class, 'login']); +// Route::post('/logout', [AuthController::class, 'logout']); +// Route::get('/profile', [AuthController::class, 'profile'])->middleware('auth:web'); + + +$controllers = require base_path('vendor/composer/autoload_classmap.php'); +$controllers = array_keys($controllers); +$controllers = array_filter($controllers, function ($controller) { + return (strpos($controller, 'TenantControllers') !== false || strpos($controller, 'MasterControllers') !== false) && strlen($controller) > 0 && strpos($controller, 'Base') == false && strpos($controller, 'OAuth') == false; +}); +array_map(function ($controller) { + if (method_exists($controller, 'routeName')) + Route::Resource($controller::routeName(), $controller); +}, $controllers); + +Route::group([ + 'prefix' => 'auth', + 'middleware' => 'web', + 'as' => 'auth.' +], function () { + $auth_routes = ['login', 'logout']; + foreach ($auth_routes as $auth_route) { + Route::post("/" . $auth_route, [AuthController::class, $auth_route])->name($auth_route); + // Route::post("/" . $auth_route, function () { + // dd("Welcome"); + // })->name($auth_route); + } + Route::get("profile", [AuthController::class, 'profile']); +});