Compare commits
53 Commits
feature/Au
...
feature/Cr
| Author | SHA1 | Date | |
|---|---|---|---|
| 85d3baa2c4 | |||
| 81401060b0 | |||
| f3a9b5e788 | |||
| d04277ece5 | |||
| e53a89016f | |||
| 53f2303253 | |||
| c6dc5256e6 | |||
| 19abb28acf | |||
| c994a3cbd0 | |||
| 431acd9279 | |||
| 9fcd8045db | |||
| 7c82556d93 | |||
| 581e7af1fd | |||
| b433d2ff52 | |||
| 6f06218cb2 | |||
| af23df5527 | |||
| 1a2077a164 | |||
| e33aac7eed | |||
| 7b0507bdda | |||
| ae8ca057fd | |||
| 32c14bd6c4 | |||
| 363c7005d0 | |||
| f29510d76e | |||
| 5596943b70 | |||
| 5831a5594a | |||
| 12736d53c5 | |||
| fda129875e | |||
| ca71547657 | |||
| 2d31eccc4a | |||
| abb92b4e22 | |||
| ea68943354 | |||
| e3831e98c9 | |||
| 9794aa1f54 | |||
| 4afcd5c81e | |||
| 74bc255d82 | |||
| ca094cff9f | |||
| c2328ec666 | |||
| e4f7b96b92 | |||
| f072bd1ee8 | |||
| f01992368e | |||
| 161fa3ae1e | |||
| 05c54fb2d7 | |||
| b32ee444ca | |||
| 264ed1ecb9 | |||
| cee480fff5 | |||
| 5024a242d2 | |||
| 0bba710b7d | |||
| f788f9a7ea | |||
| e74619d0ab | |||
| 5b42e23afc | |||
| 51aa3b157c | |||
| b24b61c754 | |||
| ccd2de26df |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
.idea
|
.idea
|
||||||
.env
|
.env
|
||||||
|
front
|
||||||
@@ -63,3 +63,15 @@ AWS_BUCKET=
|
|||||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
|
|
||||||
VITE_APP_NAME="${APP_NAME}"
|
VITE_APP_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
FIB_AUTHORIZATION_URL=
|
||||||
|
FIB_CLIENT_ID=
|
||||||
|
FIB_CLIENT_SECRET=
|
||||||
|
|
||||||
|
FIB_CREATE_PAYMENT_URL
|
||||||
|
|
||||||
|
FIB_CHECK_PAYMENT_STATUS_URL
|
||||||
|
|
||||||
|
FIB_CANCEL_PAYMENT_URL
|
||||||
|
|
||||||
|
FIB_REFUND_URL
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ ENV COMPOSER_ALLOW_SUPERUSER=1
|
|||||||
# Default command
|
# Default command
|
||||||
CMD composer install ;\
|
CMD composer install ;\
|
||||||
composer dump-autoload --optimize --classmap-authoritative ;\
|
composer dump-autoload --optimize --classmap-authoritative ;\
|
||||||
php artisan key:generate ;\
|
|
||||||
php artisan migrate ;\
|
php artisan migrate ;\
|
||||||
php artisan db:seed ;\
|
php artisan db:seed ;\
|
||||||
php-fpm
|
php-fpm
|
||||||
|
|||||||
62
backend/app/Admin/Controllers/AuthController.php
Normal file
62
backend/app/Admin/Controllers/AuthController.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Admin\Requests\Auth\LoginRequest;
|
||||||
|
use App\Admin\Requests\Auth\RegisterRequest;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Expert;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
|
class AuthController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function register(RegisterRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
Expert::query()->create([
|
||||||
|
'username' => $request->username,
|
||||||
|
'email' => $request->email,
|
||||||
|
'password' => Hash::make($request->password),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$request->session()->regenerate();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function login(LoginRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$credentials = ['password' => $request->password];
|
||||||
|
|
||||||
|
if (filter_var($request->login, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$credentials['email'] = $request->login;
|
||||||
|
} else {
|
||||||
|
$credentials['username'] = $request->login;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Auth::attempt($credentials))
|
||||||
|
{
|
||||||
|
$request->session()->regenerate();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->errorResponse(__('messages.incorrect_or_username_password'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
Auth::guard('expert')->logout();
|
||||||
|
|
||||||
|
$request->session()->invalidate();
|
||||||
|
|
||||||
|
$request->session()->regenerateToken();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
55
backend/app/Admin/Controllers/DocumentationController.php
Normal file
55
backend/app/Admin/Controllers/DocumentationController.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Admin\Requests\Documentation\RejectRequest;
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class DocumentationController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function index(Request $request): array
|
||||||
|
{
|
||||||
|
return DataTableFacade::run(
|
||||||
|
User::query(),
|
||||||
|
$request,
|
||||||
|
allowedFilters: ['*'],
|
||||||
|
allowedSortings: ['*'],
|
||||||
|
allowedSelects: [
|
||||||
|
'id', 'first_name', 'last_name', 'national_id',
|
||||||
|
'phone_number', 'postal_code', 'city_id', 'province_id',
|
||||||
|
'province_name', 'city_name', 'address'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function files(User $user): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->successResponse($user->load('documents'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function confirm(User $user): JsonResponse
|
||||||
|
{
|
||||||
|
$user->update([
|
||||||
|
'authority_level' => 1
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reject(RejectRequest $request, User $user): JsonResponse
|
||||||
|
{
|
||||||
|
$user->update([
|
||||||
|
'kyc_status' => 0,
|
||||||
|
'kyc_reject_reason' => $request->kyc_reject_reason
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
113
backend/app/Admin/Controllers/ExpertManagementController.php
Normal file
113
backend/app/Admin/Controllers/ExpertManagementController.php
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Admin\Requests\ExpertManagement\StoreRequest;
|
||||||
|
use App\Admin\Requests\ExpertManagement\UpdateRequest;
|
||||||
|
use App\Admin\Resources\ExpertManagementResource;
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\City;
|
||||||
|
use App\Models\Expert;
|
||||||
|
use App\Models\Province;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class ExpertManagementController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*/
|
||||||
|
public function index(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$data = DataTableFacade::run(
|
||||||
|
Expert::query(),
|
||||||
|
$request,
|
||||||
|
allowedFilters: ['*'],
|
||||||
|
allowedSortings: ['*'],
|
||||||
|
allowedSelects: ['id', 'username', 'first_name', 'last_name', 'phone_number', 'email', 'national_id'],
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->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($expert->load(['roles','permissions'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Admin\Requests\PermissionManagement\StoreRequest;
|
||||||
|
use App\Admin\Requests\PermissionManagement\UpdateRequest;
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Spatie\Permission\Models\Permission;
|
||||||
|
|
||||||
|
class PermissionManagementController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*/
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*/
|
||||||
|
public function index(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
57
backend/app/Admin/Controllers/ProfileController.php
Normal file
57
backend/app/Admin/Controllers/ProfileController.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Admin\Requests\Profile\ChangePasswordRequest;
|
||||||
|
use App\Admin\Requests\Profile\EditRequest;
|
||||||
|
use App\Admin\Resources\ExpertResource;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
|
class ProfileController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function info(): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->successResponse(new ExpertResource(Auth::guard('expert')->user()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(EditRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$expert = $request->user('expert');
|
||||||
|
|
||||||
|
$expert->update([
|
||||||
|
'username' => $request->username,
|
||||||
|
'first_name' => $request->first_name,
|
||||||
|
'last_name' => $request->last_name,
|
||||||
|
'email' => $expert->email,
|
||||||
|
'national_id' => $request->national_id,
|
||||||
|
'phone_number' => $request->phone_number,
|
||||||
|
'province_id' => $request->province_id,
|
||||||
|
'city_id' => $request->city_id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function changePassword(ChangePasswordRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$expert = Auth::guard('expert')->user();
|
||||||
|
|
||||||
|
if (! Hash::check($request->current_password, $expert->password))
|
||||||
|
{
|
||||||
|
return $this->errorResponse(__('messages.incorrect_current_password'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$expert->update([
|
||||||
|
'password' => Hash::make($request->new_password)
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
77
backend/app/Admin/Controllers/RoleManagementController.php
Executable file
77
backend/app/Admin/Controllers/RoleManagementController.php
Executable file
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Admin\Requests\RoleManagement\StoreRequest;
|
||||||
|
use App\Admin\Requests\RoleManagement\UpdateRequest;
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Spatie\Permission\Models\Role;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class RoleManagementController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function index(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$data = DataTableFacade::run(
|
||||||
|
Role::query(),
|
||||||
|
$request,
|
||||||
|
allowedFilters: ['*'],
|
||||||
|
allowedSortings: ['*'],
|
||||||
|
allowedSelects: ['id', 'name']
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
113
backend/app/Admin/Controllers/UserManagementController.php
Normal file
113
backend/app/Admin/Controllers/UserManagementController.php
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Admin\Requests\UserManagement\StoreRequest;
|
||||||
|
use App\Admin\Requests\UserManagement\UpdateRequest;
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\City;
|
||||||
|
use App\Models\Province;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class UserManagementController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function index(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$data = DataTableFacade::run(
|
||||||
|
User::query(),
|
||||||
|
$request,
|
||||||
|
allowedFilters: ['*'],
|
||||||
|
allowedSortings: ['*'],
|
||||||
|
allowedSelects: ['id', 'username','first_name', 'last_name','kyc_status','national_id',
|
||||||
|
'phone_number','postal_code','province_id','province_name', 'city_id', 'city_name',
|
||||||
|
'birth_date','tax_id', 'password', 'email'],
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
30
backend/app/Admin/Requests/Auth/LoginRequest.php
Normal file
30
backend/app/Admin/Requests/Auth/LoginRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\Auth;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class LoginRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'login' => 'required|string',
|
||||||
|
'password' => 'required|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
backend/app/Admin/Requests/Auth/RegisterRequest.php
Normal file
31
backend/app/Admin/Requests/Auth/RegisterRequest.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\Auth;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class RegisterRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'username' => 'required|unique:experts,username',
|
||||||
|
'email' => 'required|email|unique:experts,email',
|
||||||
|
'password' => 'required|string|regex:/^(?=.*[a-zA-Z])(?=.*\d).+$/|min:6|confirmed',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
29
backend/app/Admin/Requests/Documentation/RejectRequest.php
Normal file
29
backend/app/Admin/Requests/Documentation/RejectRequest.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\Documentation;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class RejectRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'kyc_reject_reason' => 'required|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
37
backend/app/Admin/Requests/ExpertManagement/StoreRequest.php
Normal file
37
backend/app/Admin/Requests/ExpertManagement/StoreRequest.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\ExpertManagement;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StoreRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
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',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\ExpertManagement;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property mixed $expert
|
||||||
|
*/
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
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',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\PermissionManagement;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StoreRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required|string|unique:permissions,name',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\PermissionManagement;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property mixed $permission
|
||||||
|
*/
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['required', 'string', 'max:255', Rule::unique('permissions', 'name')->ignore($this->permission->id)],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
backend/app/Admin/Requests/Profile/ChangePasswordRequest.php
Normal file
30
backend/app/Admin/Requests/Profile/ChangePasswordRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\Profile;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ChangePasswordRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'current_password' => 'required|string|regex:/^(?=.*[a-zA-Z])(?=.*\d).+$/|min:8',
|
||||||
|
'new_password' => 'required|string|regex:/^(?=.*[a-zA-Z])(?=.*\d).+$/|min:8',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
36
backend/app/Admin/Requests/Profile/EditRequest.php
Normal file
36
backend/app/Admin/Requests/Profile/EditRequest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\Profile;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class EditRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'username' => 'string|max:255',
|
||||||
|
'first_name' => 'string',
|
||||||
|
'last_name' => 'string',
|
||||||
|
'email' => 'string|email|max:255',
|
||||||
|
'national_id' => 'string',
|
||||||
|
'phone_number' => 'string',
|
||||||
|
'province_id' => 'string',
|
||||||
|
'city_id' => 'string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
backend/app/Admin/Requests/RoleManagement/StoreRequest.php
Normal file
31
backend/app/Admin/Requests/RoleManagement/StoreRequest.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\RoleManagement;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StoreRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required|string|unique:roles,name',
|
||||||
|
'permissions' => 'array',
|
||||||
|
'permissions.*' => 'integer|exists:permissions,id',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
35
backend/app/Admin/Requests/RoleManagement/UpdateRequest.php
Normal file
35
backend/app/Admin/Requests/RoleManagement/UpdateRequest.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\RoleManagement;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property mixed $role
|
||||||
|
*/
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['string', 'max:255', Rule::unique('roles', 'name')->ignore($this->role->id)],
|
||||||
|
'permissions' => 'array',
|
||||||
|
'permissions.*' => 'integer|exists:permissions,id',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
40
backend/app/Admin/Requests/UserManagement/StoreRequest.php
Normal file
40
backend/app/Admin/Requests/UserManagement/StoreRequest.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\UserManagement;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StoreRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
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',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
49
backend/app/Admin/Requests/UserManagement/UpdateRequest.php
Normal file
49
backend/app/Admin/Requests/UserManagement/UpdateRequest.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Requests\UserManagement;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property mixed $user
|
||||||
|
*/
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
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',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/app/Admin/Resources/ExpertResource.php
Normal file
24
backend/app/Admin/Resources/ExpertResource.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class ExpertResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'username' => $this->username,
|
||||||
|
'email' => $this->email,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
67
backend/app/Facades/DataTable/DataTable.php
Normal file
67
backend/app/Facades/DataTable/DataTable.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Facades\DataTable;
|
||||||
|
|
||||||
|
use App\Services\DataTable\DataTableInput;
|
||||||
|
use App\Services\DataTable\DataTableService;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Services\DataTable\Exceptions\InvalidParameterInterface;
|
||||||
|
|
||||||
|
class DataTable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Extracts data from request, passes to datatable service and prepares data for response.
|
||||||
|
* @param Model|Builder $mixed
|
||||||
|
* @param Request $request
|
||||||
|
* @param array $allowedFilters
|
||||||
|
* @param array $allowedRelations
|
||||||
|
* @param array $allowedSortings
|
||||||
|
* @param array $allowedSelects
|
||||||
|
* @return array
|
||||||
|
* @throws InvalidParameterInterface if input parameters are invalid.
|
||||||
|
*/
|
||||||
|
public function run(
|
||||||
|
Model|Builder $mixed,
|
||||||
|
Request $request,
|
||||||
|
array $allowedFilters = [],
|
||||||
|
array $allowedRelations = [],
|
||||||
|
array $allowedSortings = [],
|
||||||
|
array $allowedSelects = [],
|
||||||
|
array $allowedGroupBy = []
|
||||||
|
): array
|
||||||
|
{
|
||||||
|
|
||||||
|
$filters = json_decode($request->filters);
|
||||||
|
$sorting = json_decode($request->sorting);
|
||||||
|
$rels = $request->rels ?: array();
|
||||||
|
|
||||||
|
$dataTableInput = new DataTableInput(
|
||||||
|
$request->start,
|
||||||
|
$request->size,
|
||||||
|
$filters,
|
||||||
|
$sorting,
|
||||||
|
$rels,
|
||||||
|
$allowedFilters,
|
||||||
|
$allowedSortings,
|
||||||
|
$allowedGroupBy
|
||||||
|
);
|
||||||
|
|
||||||
|
$query = $this->makeQueryFromModel($mixed);
|
||||||
|
|
||||||
|
$dataTableService = (new DataTableService($query, $dataTableInput))
|
||||||
|
->setAllowedFilters($allowedFilters)
|
||||||
|
->setAllowedRelations($allowedRelations)
|
||||||
|
->setAllowedSortings($allowedSortings)
|
||||||
|
->setAllowedSelects($allowedSelects)
|
||||||
|
->setAllowedGroupBy($allowedGroupBy);
|
||||||
|
|
||||||
|
return $dataTableService->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function makeQueryFromModel(Model|Builder $mixed): Builder
|
||||||
|
{
|
||||||
|
return ($mixed instanceof Model) ? $mixed->query() : $mixed;
|
||||||
|
}
|
||||||
|
}
|
||||||
13
backend/app/Facades/DataTable/DataTableFacade.php
Normal file
13
backend/app/Facades/DataTable/DataTableFacade.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Facades\DataTable;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
class DataTableFacade extends Facade
|
||||||
|
{
|
||||||
|
protected static function getFacadeAccessor(): string
|
||||||
|
{
|
||||||
|
return DataTable::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
113
backend/app/Facades/File/File.php
Normal file
113
backend/app/Facades/File/File.php
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Facades\File;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Http\File as HttpFile;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
class File
|
||||||
|
{
|
||||||
|
public function save(HttpFile|UploadedFile $file, string $path, string $name = null, string $disk = 'public'): string
|
||||||
|
{
|
||||||
|
return Storage::disk($disk)->putFileAs(
|
||||||
|
$path,
|
||||||
|
$file,
|
||||||
|
$name ?? Str::uuid() . '.' . $file->extension()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filePath
|
||||||
|
* @param bool $url_is_absolute
|
||||||
|
* @param string $disk
|
||||||
|
* @return void
|
||||||
|
* @throws InvalidArgumentException when filePath is empty.
|
||||||
|
*/
|
||||||
|
public function delete(string $filePath, bool $url_is_absolute = false, string $disk = 'public'): void
|
||||||
|
{
|
||||||
|
if (!$filePath){
|
||||||
|
throw new InvalidArgumentException('File path is invalid.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($url_is_absolute) {
|
||||||
|
$needle = 'storage/';
|
||||||
|
$pos = strpos($filePath, $needle);
|
||||||
|
$filePath = substr($filePath, $pos + strlen($needle));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Storage::disk($disk)->exists($filePath)) {
|
||||||
|
Storage::disk($disk)->delete($filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteContent($file_path): bool
|
||||||
|
{
|
||||||
|
if (file_exists($file_path)) {
|
||||||
|
file_put_contents($file_path, '');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tail($file_path, $lines = 100, $buffer = 2048): bool|string
|
||||||
|
{
|
||||||
|
// Open file
|
||||||
|
$file = @fopen($file_path, "rb");
|
||||||
|
if ($file === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Jump to last character
|
||||||
|
fseek($file, -1, SEEK_END);
|
||||||
|
|
||||||
|
// Read it and adjust line number if necessary
|
||||||
|
// (Otherwise the result would be wrong if file doesn't end with a blank line)
|
||||||
|
if (fread($file, 1) != "\n") {
|
||||||
|
$lines -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start reading
|
||||||
|
$output = '';
|
||||||
|
$chunk = '';
|
||||||
|
|
||||||
|
// While we would like more
|
||||||
|
while (ftell($file) > 0 && $lines >= 0) {
|
||||||
|
|
||||||
|
// Figure out how far back we should jump
|
||||||
|
$seek = min(ftell($file), $buffer);
|
||||||
|
|
||||||
|
// Do the jump (backwards, relative to where we are)
|
||||||
|
fseek($file, -$seek, SEEK_CUR);
|
||||||
|
|
||||||
|
// Read a chunk and prepend it to our output
|
||||||
|
$output = ($chunk = fread($file, $seek)) . $output;
|
||||||
|
|
||||||
|
// Jump back to where we started reading
|
||||||
|
fseek($file, -mb_strlen($chunk, '8bit'), SEEK_CUR);
|
||||||
|
|
||||||
|
// Decrease our line counter
|
||||||
|
$lines -= substr_count($chunk, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// While we have too many lines
|
||||||
|
// (Because of buffer size we might have read too many)
|
||||||
|
while ($lines++ < 0) {
|
||||||
|
|
||||||
|
// Find first newline and remove all text before that
|
||||||
|
$output = substr($output, strpos($output, "\n") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close file and return
|
||||||
|
fclose($file);
|
||||||
|
return trim($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteDirectory(string $path, string $disk = 'public'): void
|
||||||
|
{
|
||||||
|
Storage::disk($disk)->deleteDirectory($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
backend/app/Facades/File/FileFacade.php
Normal file
13
backend/app/Facades/File/FileFacade.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Facades\File;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
class FileFacade extends Facade
|
||||||
|
{
|
||||||
|
protected static function getFacadeAccessor(): string
|
||||||
|
{
|
||||||
|
return File::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
40
backend/app/Mail/LoginNotificationMail.php
Normal file
40
backend/app/Mail/LoginNotificationMail.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Mail\Mailables\Content;
|
||||||
|
use Illuminate\Mail\Mailables\Envelope;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class LoginNotificationMail extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public User $user
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function envelope(): Envelope
|
||||||
|
{
|
||||||
|
return new Envelope(
|
||||||
|
subject: 'Login Notification Mail',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function content(): Content
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
view: 'emails.login-notification',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachments(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
15
backend/app/Models/City.php
Normal file
15
backend/app/Models/City.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Database\Factories\CityFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class City extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<CityFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
}
|
||||||
30
backend/app/Models/Document.php
Normal file
30
backend/app/Models/Document.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Database\Factories\DocumentFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
class Document extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<DocumentFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
|
public function documentable(): MorphTo
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function url(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn($value) => Storage::disk('public')->url($value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
backend/app/Models/Expert.php
Normal file
22
backend/app/Models/Expert.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Database\Factories\ExpertFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method roles()
|
||||||
|
* @method permissions()
|
||||||
|
*/
|
||||||
|
class Expert extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<ExpertFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
use HasRoles;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
protected string $guard_name = 'web';
|
||||||
|
}
|
||||||
15
backend/app/Models/Gateway.php
Normal file
15
backend/app/Models/Gateway.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Database\Factories\GatewayFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Gateway extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<GatewayFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
}
|
||||||
15
backend/app/Models/GatewayCategory.php
Normal file
15
backend/app/Models/GatewayCategory.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Database\Factories\GatewayCategoryFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class GatewayCategory extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<GatewayCategoryFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
}
|
||||||
15
backend/app/Models/Payment.php
Normal file
15
backend/app/Models/Payment.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Database\Factories\PaymentFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Payment extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<PaymentFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
}
|
||||||
15
backend/app/Models/PaymentStatus.php
Normal file
15
backend/app/Models/PaymentStatus.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Database\Factories\PaymentStatusFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class PaymentStatus extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<PaymentStatusFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
}
|
||||||
15
backend/app/Models/Province.php
Normal file
15
backend/app/Models/Province.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Database\Factories\ProvinceFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Province extends Model
|
||||||
|
{
|
||||||
|
/** @use HasFactory<ProvinceFactory> */
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
}
|
||||||
20
backend/app/Models/User.php
Normal file → Executable file
20
backend/app/Models/User.php
Normal file → Executable file
@@ -4,30 +4,24 @@ namespace App\Models;
|
|||||||
|
|
||||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
use Database\Factories\UserFactory;
|
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\Attributes\Hidden;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Laravel\Passport\HasApiTokens;
|
use Laravel\Passport\HasApiTokens;
|
||||||
|
|
||||||
#[Fillable(['name', 'email', 'password'])]
|
#[Guarded(['id'])]
|
||||||
#[Hidden(['password', 'remember_token'])]
|
#[Hidden(['password'])]
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
/** @use HasFactory<UserFactory> */
|
/** @use HasFactory<UserFactory> */
|
||||||
use HasFactory, Notifiable, HasApiTokens;
|
use HasFactory, Notifiable, HasApiTokens;
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
/**
|
public function documents(): MorphToMany
|
||||||
* Get the attributes that should be cast.
|
|
||||||
*
|
|
||||||
* @return array<string, string>
|
|
||||||
*/
|
|
||||||
protected function casts(): array
|
|
||||||
{
|
{
|
||||||
return [
|
return $this->morphToMany(Document::class, 'documentable');
|
||||||
'email_verified_at' => 'datetime',
|
|
||||||
'password' => 'hashed',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
backend/app/Providers/AppServiceProvider.php
Normal file → Executable file
2
backend/app/Providers/AppServiceProvider.php
Normal file → Executable file
@@ -4,6 +4,7 @@ namespace App\Providers;
|
|||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
|
use Carbon\CarbonInterval;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -21,5 +22,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
Passport::enablePasswordGrant();
|
Passport::enablePasswordGrant();
|
||||||
|
Passport::personalAccessTokensExpireIn(CarbonInterval::minutes(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
backend/app/Providers/DataTableServiceProvider.php
Normal file
27
backend/app/Providers/DataTableServiceProvider.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Facades\DataTable\DataTable;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class DataTableServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register services.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
$this->app->bind('datatable', function () {
|
||||||
|
return new DataTable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap services.
|
||||||
|
*/
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
27
backend/app/Providers/FileServiceProvider.php
Normal file
27
backend/app/Providers/FileServiceProvider.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Facades\File\File;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class FileServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register services.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
$this->app->bind('file', function () {
|
||||||
|
return new File();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap services.
|
||||||
|
*/
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
83
backend/app/Services/DataTable/DataTableInput.php
Normal file
83
backend/app/Services/DataTable/DataTableInput.php
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Filter\Filter;
|
||||||
|
use App\Services\DataTable\Sort\Sort;
|
||||||
|
|
||||||
|
class DataTableInput
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param int $start
|
||||||
|
* @param int $size
|
||||||
|
* @param array $filters
|
||||||
|
* @param array $sorting
|
||||||
|
* @param array $rels
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
private ?int $start,
|
||||||
|
private ?int $size,
|
||||||
|
private array $filters,
|
||||||
|
private ?array $sorting,
|
||||||
|
private array $rels,
|
||||||
|
private array $allowedFilters,
|
||||||
|
private array $allowedSortings,
|
||||||
|
private ?array $GroupBy,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStart(): ?int
|
||||||
|
{
|
||||||
|
return $this->start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSize(): ?int
|
||||||
|
{
|
||||||
|
return $this->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array returns an array of Filter objects
|
||||||
|
*/
|
||||||
|
public function getFilters(): array
|
||||||
|
{
|
||||||
|
$filters = array();
|
||||||
|
|
||||||
|
foreach ($this->filters as $filter) {
|
||||||
|
$filters[] = new Filter(
|
||||||
|
$filter->id,
|
||||||
|
$filter->value,
|
||||||
|
$filter->fn,
|
||||||
|
$filter->datatype,
|
||||||
|
$this->allowedFilters
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSorting(): ?array
|
||||||
|
{
|
||||||
|
$sorts = [];
|
||||||
|
if (!empty($this->sorting)){
|
||||||
|
foreach ($this->sorting as $sort) {
|
||||||
|
$sorts[] = new Sort($sort->id, $sort->desc, $this->allowedSortings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $sorts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRelations(): array
|
||||||
|
{
|
||||||
|
return $this->rels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroupBy(): ?array
|
||||||
|
{
|
||||||
|
return $this->GroupBy;
|
||||||
|
}
|
||||||
|
}
|
||||||
128
backend/app/Services/DataTable/DataTableService.php
Normal file
128
backend/app/Services/DataTable/DataTableService.php
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Filter\ApplyFilter;
|
||||||
|
use App\Services\DataTable\Sort\ApplySort;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class DataTableService
|
||||||
|
{
|
||||||
|
|
||||||
|
protected array $allowedFilters;
|
||||||
|
protected array $allowedRelations;
|
||||||
|
protected array $allowedSortings;
|
||||||
|
protected array $allowedSelects;
|
||||||
|
protected array $allowedGroupBy;
|
||||||
|
private int $totalRowCount;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected Builder $query,
|
||||||
|
private DataTableInput $dataTableInput
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAllowedFilters(array $allowedFilters): DataTableService
|
||||||
|
{
|
||||||
|
$this->allowedFilters = $allowedFilters;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAllowedRelations(array $allowedRelations): DataTableService
|
||||||
|
{
|
||||||
|
$this->allowedRelations = $allowedRelations;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAllowedSortings(array $allowedSortings): DataTableService
|
||||||
|
{
|
||||||
|
$this->allowedSortings = $allowedSortings;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAllowedSelects(array $allowedSelects): DataTableService
|
||||||
|
{
|
||||||
|
$this->allowedSelects = $allowedSelects;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAllowedGroupBy(array $allowedGroupBy): DataTableService
|
||||||
|
{
|
||||||
|
$this->allowedGroupBy = $allowedGroupBy;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle 'getData' operations
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getData(): array
|
||||||
|
{
|
||||||
|
$query = $this->buildQuery();
|
||||||
|
$data = $query->get();
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'data' => $data,
|
||||||
|
'meta' => [
|
||||||
|
'totalRowCount' => $this->totalRowCount
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildQuery(): Builder
|
||||||
|
{
|
||||||
|
$query = $this->query;
|
||||||
|
|
||||||
|
foreach ($this->dataTableInput->getFilters() as $filter) {
|
||||||
|
$query = (new ApplyFilter($query, $filter))->apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->applySelect($query, $this->allowedSelects);
|
||||||
|
$query = $this->includeRelationsInQuery($query, $this->allowedRelations);
|
||||||
|
$query = $this->applyGroupBy($query, $this->allowedGroupBy);
|
||||||
|
|
||||||
|
$this->totalRowCount = $query->count();
|
||||||
|
|
||||||
|
if (!is_null($this->dataTableInput->getStart())) {
|
||||||
|
$query->offset($this->dataTableInput->getStart());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!is_null($this->dataTableInput->getSize())){
|
||||||
|
$query->limit($this->dataTableInput->getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
$sorting = $this->dataTableInput->getSorting();
|
||||||
|
foreach ($sorting as $sort){
|
||||||
|
$query = (new ApplySort($query, $sort))->apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function applySelect(Builder $query, array $selectedFields): Builder
|
||||||
|
{
|
||||||
|
if (!empty($selectedFields)) {
|
||||||
|
$query->select($selectedFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function applyGroupBy(Builder $query, array $groupBy): Builder
|
||||||
|
{
|
||||||
|
return empty($groupBy) ? $query : $query->groupBy($groupBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function includeRelationsInQuery(Builder $query, array $rels): Builder
|
||||||
|
{
|
||||||
|
if (!empty($rels)) {
|
||||||
|
$query->with($rels);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (later) define mapping of relation names to prevent relation name expose.
|
||||||
|
// (later) define mapping of column names to prevent column name expose.
|
||||||
|
}
|
||||||
15
backend/app/Services/DataTable/Enums/DataType.php
Normal file
15
backend/app/Services/DataTable/Enums/DataType.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Enums;
|
||||||
|
|
||||||
|
enum DataType: string
|
||||||
|
{
|
||||||
|
case NUMERIC = 'numeric';
|
||||||
|
case TEXT = 'text';
|
||||||
|
case DATE = 'date';
|
||||||
|
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_column(self::cases(), 'value');
|
||||||
|
}
|
||||||
|
}
|
||||||
19
backend/app/Services/DataTable/Enums/SearchType.php
Normal file
19
backend/app/Services/DataTable/Enums/SearchType.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Enums;
|
||||||
|
|
||||||
|
enum SearchType: string
|
||||||
|
{
|
||||||
|
case CONTAINS = 'contains';
|
||||||
|
case EQUALS = 'equals';
|
||||||
|
case NOT_EQUALS = 'notEquals';
|
||||||
|
case BETWEEN = 'between';
|
||||||
|
case GREATER_THAN = 'greaterThan';
|
||||||
|
case LESS_THAN = 'lessThan';
|
||||||
|
case FUZZY = 'fuzzy';
|
||||||
|
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_column(self::cases(), 'value');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class InvalidFilterException extends Exception implements InvalidParameterInterface
|
||||||
|
{
|
||||||
|
protected $fieldName;
|
||||||
|
|
||||||
|
public function __construct($fieldName, $message = "", $code = 400, \Throwable $previous = null)
|
||||||
|
{
|
||||||
|
$this->fieldName = $fieldName;
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFieldName()
|
||||||
|
{
|
||||||
|
return $this->fieldName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Exceptions;
|
||||||
|
|
||||||
|
interface InvalidParameterInterface
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class InvalidRelationException extends Exception implements InvalidParameterInterface
|
||||||
|
{
|
||||||
|
protected $fieldName;
|
||||||
|
|
||||||
|
public function __construct($fieldName, $message = "", $code = 400, \Throwable $previous = null)
|
||||||
|
{
|
||||||
|
$this->fieldName = $fieldName;
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFieldName()
|
||||||
|
{
|
||||||
|
return $this->fieldName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class InvalidSortingException extends Exception implements InvalidParameterInterface
|
||||||
|
{
|
||||||
|
protected $fieldName;
|
||||||
|
|
||||||
|
public function __construct($fieldName, $message = "", $code = 400, \Throwable $previous = null)
|
||||||
|
{
|
||||||
|
$this->fieldName = $fieldName;
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFieldName()
|
||||||
|
{
|
||||||
|
return $this->fieldName;
|
||||||
|
}
|
||||||
|
}
|
||||||
84
backend/app/Services/DataTable/Filter/ApplyFilter.php
Normal file
84
backend/app/Services/DataTable/Filter/ApplyFilter.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Enums\SearchType;
|
||||||
|
use App\Services\DataTable\Exceptions\InvalidFilterException;
|
||||||
|
use App\Services\DataTable\Filter\SearchFunctions\FilterBetween;
|
||||||
|
use App\Services\DataTable\Filter\SearchFunctions\FilterContains;
|
||||||
|
use App\Services\DataTable\Filter\SearchFunctions\FilterEquals;
|
||||||
|
use App\Services\DataTable\Filter\SearchFunctions\FilterGreaterThan;
|
||||||
|
use App\Services\DataTable\Filter\SearchFunctions\FilterLessThan;
|
||||||
|
use App\Services\DataTable\Filter\SearchFunctions\FilterNotEquals;
|
||||||
|
use App\Services\DataTable\Filter\SearchFunctions\SearchFilter;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class ApplyFilter
|
||||||
|
{
|
||||||
|
private SearchFilter $searchFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Builder $query
|
||||||
|
* @param Filter $filter
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
private Builder $query,
|
||||||
|
private Filter $filter,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$filter = $this->filter;
|
||||||
|
$query = $this->query;
|
||||||
|
|
||||||
|
$searchType = SearchType::from($filter->getFn());
|
||||||
|
switch ($searchType) {
|
||||||
|
case SearchType::CONTAINS:
|
||||||
|
$this->searchFilter = new FilterContains($query, $filter);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SearchType::EQUALS:
|
||||||
|
$this->searchFilter = new FilterEquals($query, $filter);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SearchType::NOT_EQUALS:
|
||||||
|
$this->searchFilter = new FilterNotEquals($query, $filter);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SearchType::BETWEEN:
|
||||||
|
$this->searchFilter = new FilterBetween($query, $filter);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SearchType::GREATER_THAN:
|
||||||
|
$this->searchFilter = new FilterGreaterThan($query, $filter);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SearchType::LESS_THAN:
|
||||||
|
$this->searchFilter = new FilterLessThan($query, $filter);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$searchFunction = $filter->getFn();
|
||||||
|
throw new InvalidFilterException($searchFunction, "search function `$searchFunction` is invalid.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$relation = $this->filter->getRelation();
|
||||||
|
return method_exists($this->query->getModel(), $relation) ? $this->applyFilterToRelation($relation) : $this->searchFilter->apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function applyFilterToRelation(string $relation): Builder
|
||||||
|
{
|
||||||
|
return $this->query->whereHas($relation, function (Builder $query) {
|
||||||
|
$this->filter->removeRelationFromId();
|
||||||
|
$this->applyFilter($query, $this->filter);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function applyFilter(Builder $query, Filter $filter): Builder
|
||||||
|
{
|
||||||
|
return (new ApplyFilter($query, $filter))->apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
73
backend/app/Services/DataTable/Filter/Filter.php
Normal file
73
backend/app/Services/DataTable/Filter/Filter.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Validators\FilterValidator;
|
||||||
|
|
||||||
|
class Filter
|
||||||
|
{
|
||||||
|
private static FilterValidator $filterValidator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $id
|
||||||
|
* @param string|int|array $value
|
||||||
|
* @param string $fn
|
||||||
|
* @param string $datatype
|
||||||
|
* @param array $allowedFilters
|
||||||
|
* @throws \App\Services\DataTable\Exceptions\InvalidFilterException
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
private string $id,
|
||||||
|
private string|int|array $value,
|
||||||
|
private string $fn,
|
||||||
|
private string $datatype,
|
||||||
|
private array $allowedFilters
|
||||||
|
)
|
||||||
|
{
|
||||||
|
self::$filterValidator = FilterValidator::getInstance();
|
||||||
|
self::$filterValidator->isValid($this, $this->allowedFilters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): string
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue(): array|int|string
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFn(): string
|
||||||
|
{
|
||||||
|
return $this->fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDatatype(): string
|
||||||
|
{
|
||||||
|
return $this->datatype;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRelation(): string
|
||||||
|
{
|
||||||
|
$fieldArray = explode('.', $this->id);
|
||||||
|
return count($fieldArray) > 1 ? $fieldArray[0] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColumn(): string
|
||||||
|
{
|
||||||
|
$fieldArray = explode('.', $this->id);
|
||||||
|
return array_pop($fieldArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeRelationFromId(): void
|
||||||
|
{
|
||||||
|
$this->id = $this->getColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue(int|array|string $value): void
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter\SearchFunctions;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class FilterBetween extends SearchFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$query = $this->query;
|
||||||
|
[$minVal, $maxVal] = $this->filter->getValue();
|
||||||
|
|
||||||
|
if ($minVal) {
|
||||||
|
if ($this->filter->getDatatype() == "date") {
|
||||||
|
$minVal = $minVal . " 00:00:00";
|
||||||
|
}
|
||||||
|
$this->filter->setValue($minVal);
|
||||||
|
$query = (new FilterGreaterThanOrEqual($this->query, $this->filter))->apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($maxVal) {
|
||||||
|
if ($this->filter->getDatatype() == "date") {
|
||||||
|
$maxVal = $maxVal . " 23:59:59";
|
||||||
|
}
|
||||||
|
$this->filter->setValue($maxVal);
|
||||||
|
$query = (new FilterLessThanOrEqual($this->query, $this->filter))->apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter\SearchFunctions;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Enums\DataType;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class FilterContains extends SearchFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$column = $this->filter->getId();
|
||||||
|
$value = '%' . $this->filter->getValue() . '%';
|
||||||
|
|
||||||
|
if ($this->filter->getDatatype() == DataType::TEXT->value) {
|
||||||
|
$query = $this->searchIgnoreCase($column, $value);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$query = $this->query->where($column, 'LIKE', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function searchIgnoreCase(string $column, string $value): Builder
|
||||||
|
{
|
||||||
|
$value = strtolower($value);
|
||||||
|
return $this->query->whereRaw("LOWER($column) LIKE ?", [$value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter\SearchFunctions;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Enums\DataType;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class FilterEquals extends SearchFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$column = $this->filter->getId();
|
||||||
|
$value = $this->filter->getValue();
|
||||||
|
|
||||||
|
if ($this->filter->getDatatype() == DataType::TEXT->value) {
|
||||||
|
$query = $this->searchIgnoreCase($column, $value);
|
||||||
|
} else {
|
||||||
|
$query = $this->query->where($column, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function searchIgnoreCase(string $column, string $value): Builder
|
||||||
|
{
|
||||||
|
$value = strtolower($value);
|
||||||
|
return $this->query->whereRaw("LOWER($column) = ?", [$value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter\SearchFunctions;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Enums\DataType;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class FilterGreaterThan extends SearchFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$value = ($this->filter->getDatatype() == DataType::NUMERIC) ?
|
||||||
|
(float)$this->filter->getValue() : $this->filter->getValue();
|
||||||
|
|
||||||
|
return $this->query->where($this->filter->getId(), '>', $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter\SearchFunctions;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Enums\DataType;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class FilterGreaterThanOrEqual extends SearchFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$value = ($this->filter->getDatatype() == DataType::NUMERIC) ?
|
||||||
|
(float)$this->filter->getValue() : $this->filter->getValue();
|
||||||
|
|
||||||
|
return $this->query->where($this->filter->getId(), '>=', $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter\SearchFunctions;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Enums\DataType;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class FilterLessThan extends SearchFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$value = ($this->filter->getDatatype() == DataType::NUMERIC) ?
|
||||||
|
(float)$this->filter->getValue() : $this->filter->getValue();
|
||||||
|
|
||||||
|
return $this->query->where($this->filter->getId(), '<', $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter\SearchFunctions;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Enums\DataType;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class FilterLessThanOrEqual extends SearchFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$value = ($this->filter->getDatatype() == DataType::NUMERIC) ?
|
||||||
|
(float)$this->filter->getValue() : $this->filter->getValue();
|
||||||
|
|
||||||
|
return $this->query->where($this->filter->getId(), '<=', $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter\SearchFunctions;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class FilterNotEquals extends SearchFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$column = $this->filter->getId();
|
||||||
|
$value = $this->filter->getValue();
|
||||||
|
|
||||||
|
return $this->query->whereNot($column, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Filter\SearchFunctions;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Filter\Filter;
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
abstract class SearchFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Builder $query
|
||||||
|
* @param Filter $filter
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
protected Builder $query,
|
||||||
|
protected Filter $filter,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function apply(): Builder;
|
||||||
|
}
|
||||||
31
backend/app/Services/DataTable/Sort/ApplySort.php
Normal file
31
backend/app/Services/DataTable/Sort/ApplySort.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Sort;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Query\Builder;
|
||||||
|
|
||||||
|
class ApplySort
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Builder $query
|
||||||
|
* @param ?Sort $sort
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
private Builder $query,
|
||||||
|
private ?Sort $sort,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function apply(): Builder
|
||||||
|
{
|
||||||
|
$query = $this->query;
|
||||||
|
|
||||||
|
if (!is_null($this->sort)) {
|
||||||
|
$query->orderBy($this->sort->getId(), $this->sort->getDirection());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
}
|
||||||
39
backend/app/Services/DataTable/Sort/Sort.php
Normal file
39
backend/app/Services/DataTable/Sort/Sort.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Sort;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Validators\SortingValidator;
|
||||||
|
|
||||||
|
class Sort
|
||||||
|
{
|
||||||
|
private static SortingValidator $sortingValidator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $id
|
||||||
|
* @param bool $desc
|
||||||
|
* @param array $allowedSortings
|
||||||
|
* @throws \App\Services\DataTable\Exceptions\InvalidSortingException
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
private string $id,
|
||||||
|
private bool $desc,
|
||||||
|
private array $allowedSortings,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
self::$sortingValidator = SortingValidator::getInstance();
|
||||||
|
self::$sortingValidator->isValid($this, $this->allowedSortings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getId(): string
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDirection(): string
|
||||||
|
{
|
||||||
|
return $this->desc === true ? 'desc' : 'asc';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Validators;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Enums\SearchType;
|
||||||
|
use App\Services\DataTable\Enums\DataType;
|
||||||
|
use App\Services\DataTable\Exceptions\InvalidFilterException;
|
||||||
|
use App\Services\DataTable\Filter\Filter;
|
||||||
|
|
||||||
|
class FilterValidator
|
||||||
|
{
|
||||||
|
private static $instance;
|
||||||
|
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInstance(): FilterValidator
|
||||||
|
{
|
||||||
|
if (!isset(self::$instance)) {
|
||||||
|
self::$instance = new static();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValid(Filter $filter, array $allowedFilters): bool
|
||||||
|
{
|
||||||
|
if (!$this->isAllowed($filter, $allowedFilters)) {
|
||||||
|
$filterId = $filter->getId();
|
||||||
|
throw new InvalidFilterException($filter->getId(), "filtering field `$filterId` is not allowed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->isValidSearchFunction($filter)) {
|
||||||
|
$searchFunction = $filter->getFn();
|
||||||
|
throw new InvalidFilterException($searchFunction, "search function `$searchFunction` is invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isValidDataType($filter) == -1) {
|
||||||
|
throw new InvalidFilterException(null, "datatype property is not set in `filters` array.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->isValidDataType($filter)) {
|
||||||
|
$datatype = $filter->getDatatype();
|
||||||
|
throw new InvalidFilterException($datatype, "datatype `$datatype` is invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isAllowed(Filter $filter, array $allowedFilters): bool
|
||||||
|
{
|
||||||
|
return $allowedFilters == ['*'] || in_array($filter->getId(), $allowedFilters);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isValidSearchFunction(Filter $filter): bool
|
||||||
|
{
|
||||||
|
$searchFunction = $filter->getFn();
|
||||||
|
return isset($searchFunction) && in_array($searchFunction, SearchType::values());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isValidDataType(Filter $filter): int
|
||||||
|
{
|
||||||
|
if (!property_exists($filter, 'datatype'))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return $filter->getDatatype() && in_array($filter->getDatatype(), DataType::values()) ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Validators;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Exceptions\InvalidRelationException;
|
||||||
|
|
||||||
|
class RelationValidator
|
||||||
|
{
|
||||||
|
public static function validate(?array $rels, array $allowedRelations): bool
|
||||||
|
{
|
||||||
|
foreach ($rels as $relation) {
|
||||||
|
|
||||||
|
if (!self::isAllowed($relation, $allowedRelations)) {
|
||||||
|
throw new InvalidRelationException($relation, "relation `$relation` is not allowed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isAllowed(string $relation, array $allowedRelations): bool
|
||||||
|
{
|
||||||
|
return !$relation || in_array($relation, $allowedRelations);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\DataTable\Validators;
|
||||||
|
|
||||||
|
use App\Services\DataTable\Exceptions\InvalidSortingException;
|
||||||
|
use App\Services\DataTable\Sort\Sort;
|
||||||
|
|
||||||
|
class SortingValidator
|
||||||
|
{
|
||||||
|
private static $instance;
|
||||||
|
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInstance(): SortingValidator
|
||||||
|
{
|
||||||
|
if (!isset(self::$instance)) {
|
||||||
|
self::$instance = new static();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValid(Sort $sorting, array $allowedSortings): bool
|
||||||
|
{
|
||||||
|
if (!$this->isAllowed($sorting, $allowedSortings)) {
|
||||||
|
$sortId = $sorting->getId();
|
||||||
|
throw new InvalidSortingException($sortId, "sorting field `$sortId` is not allowed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isAllowed(Sort $sorting, array $allowedSortings): bool
|
||||||
|
{
|
||||||
|
return $allowedSortings == ['*'] || in_array($sorting->getId(), $allowedSortings);
|
||||||
|
}
|
||||||
|
}
|
||||||
31
backend/app/Traits/ApiResponse.php
Executable file
31
backend/app/Traits/ApiResponse.php
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Traits;
|
||||||
|
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
trait ApiResponse
|
||||||
|
{
|
||||||
|
public function successResponse(mixed $data = null, string $message = null, int $statusCode = 200): JsonResponse
|
||||||
|
{
|
||||||
|
if (!is_null($data)) {
|
||||||
|
return response()->json([
|
||||||
|
'data' => $data
|
||||||
|
], $statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = $message ?? __('messages.successful');
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => $message
|
||||||
|
], $statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function errorResponse(string $message, string $type = 'logical_exception', int $statusCode = 422): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'type' => $type,
|
||||||
|
'message' => $message
|
||||||
|
], $statusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
64
backend/app/User/Controllers/AuthController.php
Normal file
64
backend/app/User/Controllers/AuthController.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use App\User\Requests\Auth\LoginRequest;
|
||||||
|
use App\User\Requests\Auth\RegisterRequest;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
|
class AuthController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function register(RegisterRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$user = User::query()->create([
|
||||||
|
'username' => $request->username,
|
||||||
|
'email' => $request->email,
|
||||||
|
'password' => Hash::make($request->password),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Auth::guard('web')->login($user);
|
||||||
|
|
||||||
|
$request->session()->regenerate();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function login(LoginRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$credentials = ['password' => $request->password,];
|
||||||
|
|
||||||
|
if (filter_var($request->login, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$credentials['email'] = $request->login;
|
||||||
|
} else {
|
||||||
|
$credentials['username'] = $request->login;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Auth::attempt($credentials))
|
||||||
|
{
|
||||||
|
$request->session()->regenerate();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->errorResponse(__('messages.incorrect_or_username_password'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
Auth::guard('web')->logout();
|
||||||
|
|
||||||
|
$request->session()->invalidate();
|
||||||
|
|
||||||
|
$request->session()->regenerateToken();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
backend/app/User/Controllers/Dashboard/ConfirmController.php
Executable file
14
backend/app/User/Controllers/Dashboard/ConfirmController.php
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Controllers\Dashboard;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class ConfirmController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/app/User/Controllers/Dashboard/DocumentationController.php
Executable file
24
backend/app/User/Controllers/Dashboard/DocumentationController.php
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Controller\Dashboard;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class DocumentationController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function store(StoreRequest $request): jsonResponse
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(UpdateRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
42
backend/app/User/Controllers/DocumentationController.php
Executable file
42
backend/app/User/Controllers/DocumentationController.php
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Controllers;
|
||||||
|
|
||||||
|
use App\Facades\File\FileFacade;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use App\User\Requests\Documentation\EditRequest;
|
||||||
|
use App\User\Requests\Documentation\UploadRequest;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class DocumentationController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function upload(UploadRequest $request): jsonResponse
|
||||||
|
{
|
||||||
|
$user = Auth::guard('web')->user();
|
||||||
|
|
||||||
|
foreach ($request->documents as $document) {
|
||||||
|
$user->documents()->create([
|
||||||
|
'title' => $document['title'],
|
||||||
|
'url' => FileFacade::save($document['file'], "/{$user->id}/documents", $document['title']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(EditRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$user = Auth::guard('web')->user();
|
||||||
|
|
||||||
|
foreach ($request->documents as $document) {
|
||||||
|
$user->documents()->sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
56
backend/app/User/Controllers/ProfileController.php
Normal file
56
backend/app/User/Controllers/ProfileController.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use App\User\Requests\Profile\ChangePasswordRequest;
|
||||||
|
use App\User\Requests\Profile\EditRequest;
|
||||||
|
use App\User\Resources\UserResource;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
|
class ProfileController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function info(): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->successResponse(new UserResource(Auth::user()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(EditRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
|
$user->update([
|
||||||
|
'first_name' => $request->first_name,
|
||||||
|
'last_name' => $request->last_name,
|
||||||
|
'national_id' => $request->national_id,
|
||||||
|
'address' => $request->address,
|
||||||
|
'postal_code' => $request->postal_code,
|
||||||
|
'phone_number' => $request->phone_number,
|
||||||
|
'province_id' => $request->province_id,
|
||||||
|
'city_id' => $request->city_id,
|
||||||
|
'status' => 1
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function changePassword(ChangePasswordRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
|
if (! Hash::check($request->current_password, $user->password)) {
|
||||||
|
return $this->errorResponse(__('messages.incorrect_current_password'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->update([
|
||||||
|
'password' => Hash::make($request->new_password),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
23
backend/app/User/Events/LoginEmailEvent.php
Executable file
23
backend/app/User/Events/LoginEmailEvent.php
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Events;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Broadcasting\Channel;
|
||||||
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
|
use Illuminate\Broadcasting\PrivateChannel;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class LoginEmailEvent
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*/
|
||||||
|
public function __construct(public User $user)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
31
backend/app/User/Listeners/SendEmailListener.php
Executable file
31
backend/app/User/Listeners/SendEmailListener.php
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Listeners;
|
||||||
|
|
||||||
|
use App\Mail\LoginNotificationMail;
|
||||||
|
use App\User\Events\LoginEmailEvent;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
class SendEmailListener implements ShouldQueue{
|
||||||
|
public string $queue = 'emails';
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*/
|
||||||
|
public function handle(LoginEmailEvent $event): void
|
||||||
|
{
|
||||||
|
$user = $event->user;
|
||||||
|
|
||||||
|
Mail::to($user->email)->send(
|
||||||
|
new LoginNotificationMail($user)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
backend/app/User/Requests/Auth/LoginRequest.php
Normal file
30
backend/app/User/Requests/Auth/LoginRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Requests\Auth;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class LoginRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'login' => 'required|string',
|
||||||
|
'password' => 'required|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
backend/app/User/Requests/Auth/RegisterRequest.php
Normal file
31
backend/app/User/Requests/Auth/RegisterRequest.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Requests\Auth;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class RegisterRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'username' => 'required|unique:users,username',
|
||||||
|
'email' => 'required|email|unique:users,email',
|
||||||
|
'password' => 'required|string|regex:/^(?=.*[a-zA-Z])(?=.*\d).+$/|min:6|confirmed',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
backend/app/User/Requests/Documentation/EditRequest.php
Executable file
31
backend/app/User/Requests/Documentation/EditRequest.php
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Requests\Documentation;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class EditRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'documents' => 'required|array',
|
||||||
|
'documents.*.file' => 'required|file|mimes:pdf,jpg,jpeg,png|max:2048',
|
||||||
|
'documents.*.title' => 'required|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
backend/app/User/Requests/Documentation/UploadRequest.php
Executable file
31
backend/app/User/Requests/Documentation/UploadRequest.php
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Requests\Documentation;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UploadRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'documents' => 'required|array',
|
||||||
|
'documents.*.file' => 'required|file|mimes:pdf,jpg,jpeg,png|max:2048',
|
||||||
|
'documents.*.title' => 'required|string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
backend/app/User/Requests/Profile/ChangePasswordRequest.php
Normal file
30
backend/app/User/Requests/Profile/ChangePasswordRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Requests\Profile;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ChangePasswordRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'current_password' => 'required|string|regex:/^(?=.*[a-zA-Z])(?=.*\d).+$/|min:6',
|
||||||
|
'new_password' => 'required|string|regex:/^(?=.*[a-zA-Z])(?=.*\d).+$/|min:6',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
36
backend/app/User/Requests/Profile/EditRequest.php
Normal file
36
backend/app/User/Requests/Profile/EditRequest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Requests\Profile;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class EditRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'first_name' => 'required|string',
|
||||||
|
'last_name' => 'required|string',
|
||||||
|
'national_id' => 'required',
|
||||||
|
'address' => 'required',
|
||||||
|
'postal_code' => 'required',
|
||||||
|
'phone_number' => 'required',
|
||||||
|
'province_id' => 'required',
|
||||||
|
'city_id' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
23
backend/app/User/Resources/UserResource.php
Normal file
23
backend/app/User/Resources/UserResource.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class UserResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'username' => $this->username,
|
||||||
|
'email' => $this->email,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,10 +17,6 @@ class AuthorizationService
|
|||||||
{
|
{
|
||||||
$this->url = config('fib.authorization.url');
|
$this->url = config('fib.authorization.url');
|
||||||
$this->channelName = '';
|
$this->channelName = '';
|
||||||
}
|
|
||||||
|
|
||||||
public function setInputParameters(): void
|
|
||||||
{
|
|
||||||
$this->inputParameters = [
|
$this->inputParameters = [
|
||||||
'client_id' => config('fib.authorization.client_id'),
|
'client_id' => config('fib.authorization.client_id'),
|
||||||
'client_secret' => config('fib.authorization.client_secret'),
|
'client_secret' => config('fib.authorization.client_secret'),
|
||||||
@@ -53,7 +49,7 @@ class AuthorizationService
|
|||||||
*/
|
*/
|
||||||
public function sendRequest(): array
|
public function sendRequest(): array
|
||||||
{
|
{
|
||||||
return Http::withHeaders(['Content-Type' => 'application/json'])
|
return Http::asForm()
|
||||||
->throw()
|
->throw()
|
||||||
->withoutVerifying()
|
->withoutVerifying()
|
||||||
->post($this->url, $this->inputParameters)
|
->post($this->url, $this->inputParameters)
|
||||||
|
|||||||
13
backend/bootstrap/app.php
Normal file → Executable file
13
backend/bootstrap/app.php
Normal file → Executable file
@@ -10,10 +10,19 @@ return Application::configure(basePath: dirname(__DIR__))
|
|||||||
api: __DIR__.'/../routes/api.php',
|
api: __DIR__.'/../routes/api.php',
|
||||||
commands: __DIR__.'/../routes/console.php',
|
commands: __DIR__.'/../routes/console.php',
|
||||||
health: '/up',
|
health: '/up',
|
||||||
|
then: function () {
|
||||||
|
Route::middleware('web')
|
||||||
|
->prefix('expert')
|
||||||
|
->name('expert.')
|
||||||
|
->group(base_path('routes/expert.php'));
|
||||||
|
},
|
||||||
)
|
)
|
||||||
->withMiddleware(function (Middleware $middleware): void {
|
->withMiddleware(function (Middleware $middleware): void {
|
||||||
//
|
$middleware->web()->preventRequestForgery(['*']);
|
||||||
})
|
})
|
||||||
->withExceptions(function (Exceptions $exceptions): void {
|
->withExceptions(function (Exceptions $exceptions): void {
|
||||||
//
|
//
|
||||||
})->create();
|
})
|
||||||
|
->withEvents(discover: [
|
||||||
|
__DIR__.'/../app/User/Listeners',
|
||||||
|
])->create();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Providers\AppServiceProvider;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
AppServiceProvider::class,
|
App\Providers\AppServiceProvider::class,
|
||||||
|
App\Providers\DataTableServiceProvider::class,
|
||||||
|
App\Providers\FileServiceProvider::class,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
"php": "^8.3",
|
"php": "^8.3",
|
||||||
"laravel/framework": "^13.0",
|
"laravel/framework": "^13.0",
|
||||||
"laravel/passport": "^13.0",
|
"laravel/passport": "^13.0",
|
||||||
"laravel/tinker": "^3.0"
|
"laravel/tinker": "^3.0",
|
||||||
|
"spatie/laravel-permission": "^7.4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.23",
|
"fakerphp/faker": "^1.23",
|
||||||
|
|||||||
150
backend/composer.lock
generated
150
backend/composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "7298a47753c91eab121f7ef9a163f9f2",
|
"content-hash": "aaa8c08c593e524845dc3c1a83a79433",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
@@ -4218,6 +4218,154 @@
|
|||||||
},
|
},
|
||||||
"time": "2025-12-14T04:43:48+00:00"
|
"time": "2025-12-14T04:43:48+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "spatie/laravel-package-tools",
|
||||||
|
"version": "1.93.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/spatie/laravel-package-tools.git",
|
||||||
|
"reference": "0d097bce95b2bf6802fb1d83e1e753b0f5a948e7"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/0d097bce95b2bf6802fb1d83e1e753b0f5a948e7",
|
||||||
|
"reference": "0d097bce95b2bf6802fb1d83e1e753b0f5a948e7",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"illuminate/contracts": "^10.0|^11.0|^12.0|^13.0",
|
||||||
|
"php": "^8.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mockery/mockery": "^1.5",
|
||||||
|
"orchestra/testbench": "^8.0|^9.2|^10.0|^11.0",
|
||||||
|
"pestphp/pest": "^2.1|^3.1|^4.0",
|
||||||
|
"phpunit/php-code-coverage": "^10.0|^11.0|^12.0",
|
||||||
|
"phpunit/phpunit": "^10.5|^11.5|^12.5",
|
||||||
|
"spatie/pest-plugin-test-time": "^2.2|^3.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Spatie\\LaravelPackageTools\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Freek Van der Herten",
|
||||||
|
"email": "freek@spatie.be",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Tools for creating Laravel packages",
|
||||||
|
"homepage": "https://github.com/spatie/laravel-package-tools",
|
||||||
|
"keywords": [
|
||||||
|
"laravel-package-tools",
|
||||||
|
"spatie"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/spatie/laravel-package-tools/issues",
|
||||||
|
"source": "https://github.com/spatie/laravel-package-tools/tree/1.93.0"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/spatie",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2026-02-21T12:49:54+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "spatie/laravel-permission",
|
||||||
|
"version": "7.4.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/spatie/laravel-permission.git",
|
||||||
|
"reference": "ef42ecb781e5534d368a3853fa161e420ad51397"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/spatie/laravel-permission/zipball/ef42ecb781e5534d368a3853fa161e420ad51397",
|
||||||
|
"reference": "ef42ecb781e5534d368a3853fa161e420ad51397",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"illuminate/auth": "^12.0|^13.0",
|
||||||
|
"illuminate/container": "^12.0|^13.0",
|
||||||
|
"illuminate/contracts": "^12.0|^13.0",
|
||||||
|
"illuminate/database": "^12.0|^13.0",
|
||||||
|
"php": "^8.3",
|
||||||
|
"spatie/laravel-package-tools": "^1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"larastan/larastan": "^3.9",
|
||||||
|
"laravel/passport": "^13.0",
|
||||||
|
"laravel/pint": "^1.0",
|
||||||
|
"orchestra/testbench": "^10.0|^11.0",
|
||||||
|
"pestphp/pest": "^3.0|^4.0",
|
||||||
|
"pestphp/pest-plugin-laravel": "^3.0|^4.1",
|
||||||
|
"phpstan/phpstan": "^2.1"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"Spatie\\Permission\\PermissionServiceProvider"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "7.x-dev",
|
||||||
|
"dev-master": "7.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"src/helpers.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Spatie\\Permission\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Freek Van der Herten",
|
||||||
|
"email": "freek@spatie.be",
|
||||||
|
"homepage": "https://spatie.be",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Permission handling for Laravel 12 and up",
|
||||||
|
"homepage": "https://github.com/spatie/laravel-permission",
|
||||||
|
"keywords": [
|
||||||
|
"acl",
|
||||||
|
"laravel",
|
||||||
|
"permission",
|
||||||
|
"permissions",
|
||||||
|
"rbac",
|
||||||
|
"roles",
|
||||||
|
"security",
|
||||||
|
"spatie"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/spatie/laravel-permission/issues",
|
||||||
|
"source": "https://github.com/spatie/laravel-permission/tree/7.4.1"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/spatie",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2026-04-29T07:59:45+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/clock",
|
"name": "symfony/clock",
|
||||||
"version": "v8.0.8",
|
"version": "v8.0.8",
|
||||||
|
|||||||
8
backend/config/auth.php
Normal file → Executable file
8
backend/config/auth.php
Normal file → Executable file
@@ -46,6 +46,10 @@ return [
|
|||||||
'driver' => 'passport',
|
'driver' => 'passport',
|
||||||
'provider' => 'users',
|
'provider' => 'users',
|
||||||
],
|
],
|
||||||
|
'expert' => [
|
||||||
|
'driver' => 'session',
|
||||||
|
'provider' => 'experts',
|
||||||
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -70,6 +74,10 @@ return [
|
|||||||
'driver' => 'eloquent',
|
'driver' => 'eloquent',
|
||||||
'model' => env('AUTH_MODEL', User::class),
|
'model' => env('AUTH_MODEL', User::class),
|
||||||
],
|
],
|
||||||
|
'experts' => [
|
||||||
|
'driver' => 'eloquent',
|
||||||
|
'model' => env('AUTH_MODEL', Expert::class),
|
||||||
|
],
|
||||||
|
|
||||||
// 'users' => [
|
// 'users' => [
|
||||||
// 'driver' => 'database',
|
// 'driver' => 'database',
|
||||||
|
|||||||
34
backend/config/cors.php
Executable file
34
backend/config/cors.php
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Cross-Origin Resource Sharing (CORS) Configuration
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may configure your settings for cross-origin resource sharing
|
||||||
|
| or "CORS". This determines what cross-origin operations may execute
|
||||||
|
| in web browsers. You are free to adjust these settings as needed.
|
||||||
|
|
|
||||||
|
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'paths' => ['*'],
|
||||||
|
|
||||||
|
'allowed_methods' => ['*'],
|
||||||
|
|
||||||
|
'allowed_origins' => ['*'],
|
||||||
|
|
||||||
|
'allowed_origins_patterns' => [],
|
||||||
|
|
||||||
|
'allowed_headers' => ['*'],
|
||||||
|
|
||||||
|
'exposed_headers' => [],
|
||||||
|
|
||||||
|
'max_age' => 0,
|
||||||
|
|
||||||
|
'supports_credentials' => true,
|
||||||
|
|
||||||
|
];
|
||||||
219
backend/config/permission.php
Normal file
219
backend/config/permission.php
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Spatie\Permission\DefaultTeamResolver;
|
||||||
|
use Spatie\Permission\Models\Permission;
|
||||||
|
use Spatie\Permission\Models\Role;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
'models' => [
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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',
|
||||||
|
],
|
||||||
|
];
|
||||||
0
backend/config/session.php
Normal file → Executable file
0
backend/config/session.php
Normal file → Executable file
24
backend/database/factories/CityFactory.php
Normal file
24
backend/database/factories/CityFactory.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\City;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<City>
|
||||||
|
*/
|
||||||
|
class CityFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/database/factories/DocumentFactory.php
Normal file
24
backend/database/factories/DocumentFactory.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Document;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<Document>
|
||||||
|
*/
|
||||||
|
class DocumentFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/database/factories/ExpertFactory.php
Normal file
24
backend/database/factories/ExpertFactory.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Expert;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<Expert>
|
||||||
|
*/
|
||||||
|
class ExpertFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/database/factories/GatewayCategoryFactory.php
Normal file
24
backend/database/factories/GatewayCategoryFactory.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\GatewayCategory;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<GatewayCategory>
|
||||||
|
*/
|
||||||
|
class GatewayCategoryFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/database/factories/GatewayFactory.php
Normal file
24
backend/database/factories/GatewayFactory.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Gateway;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<Gateway>
|
||||||
|
*/
|
||||||
|
class GatewayFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/database/factories/PaymentFactory.php
Normal file
24
backend/database/factories/PaymentFactory.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Payment;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<Payment>
|
||||||
|
*/
|
||||||
|
class PaymentFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/database/factories/PaymentStatusFactory.php
Normal file
24
backend/database/factories/PaymentStatusFactory.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\PaymentStatus;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<PaymentStatus>
|
||||||
|
*/
|
||||||
|
class PaymentStatusFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
backend/database/factories/ProvinceFactory.php
Normal file
24
backend/database/factories/ProvinceFactory.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Province;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<Province>
|
||||||
|
*/
|
||||||
|
class ProvinceFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
2
backend/database/factories/UserFactory.php
Normal file → Executable file
2
backend/database/factories/UserFactory.php
Normal file → Executable file
@@ -25,7 +25,7 @@ class UserFactory extends Factory
|
|||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => fake()->name(),
|
'username' => fake()->name(),
|
||||||
'email' => fake()->unique()->safeEmail(),
|
'email' => fake()->unique()->safeEmail(),
|
||||||
'email_verified_at' => now(),
|
'email_verified_at' => now(),
|
||||||
'password' => static::$password ??= Hash::make('password'),
|
'password' => static::$password ??= Hash::make('password'),
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('provinces', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('provinces');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('cities', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->foreignId('province_id')->constrained('provinces');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('cities');
|
||||||
|
}
|
||||||
|
};
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user