├── .editorconfig ├── .env.example ├── .gitattributes ├── .gitignore ├── README.md ├── app ├── Actions │ └── Fortify │ │ ├── CreateNewUser.php │ │ ├── PasswordValidationRules.php │ │ ├── ResetUserPassword.php │ │ ├── UpdateUserPassword.php │ │ └── UpdateUserProfileInformation.php ├── Http │ ├── Controllers │ │ ├── AuthController.php │ │ ├── Controller.php │ │ ├── RoleController.php │ │ ├── SpaController.php │ │ ├── TokenController.php │ │ └── UserController.php │ ├── Middleware │ │ ├── ApplyLocale.php │ │ └── RedirectIfAuthenticated.php │ ├── Requests │ │ ├── BaseRequest.php │ │ ├── DestroyUserRequest.php │ │ ├── StoreUserRequest.php │ │ ├── UpdateAvatarRequest.php │ │ └── UpdateUserRequest.php │ ├── Resources │ │ ├── RoleResource.php │ │ ├── UserBasicResource.php │ │ └── UserResource.php │ └── Responses │ │ └── LoginResponse.php ├── Models │ ├── Role.php │ └── User.php ├── Providers │ ├── AppServiceProvider.php │ └── FortifyServiceProvider.php ├── Services │ ├── Media │ │ └── MediaService.php │ ├── Role │ │ └── RoleService.php │ └── User │ │ └── UserService.php ├── Traits │ ├── Filterable.php │ └── Searchable.php └── Utilities │ └── Data.php ├── artisan ├── bootstrap ├── app.php ├── cache │ └── .gitignore └── providers.php ├── composer.json ├── config ├── .gitkeep ├── cors.php ├── database.php ├── fortify.php ├── ide-helper.php ├── mail.php ├── sanctum.php └── services.php ├── database ├── .gitignore ├── factories │ └── UserFactory.php ├── migrations │ ├── 0001_01_01_000000_create_users_table.php │ ├── 0001_01_01_000001_create_cache_table.php │ ├── 0001_01_01_000002_create_jobs_table.php │ ├── 2014_10_12_200000_add_two_factor_columns_to_users_table.php │ ├── 2019_12_14_000001_create_personal_access_tokens_table.php │ ├── 2022_11_18_212346_create_bouncer_tables.php │ └── 2023_10_07_114319_create_media_table.php └── seeders │ ├── BouncerSeeder.php │ ├── DatabaseSeeder.php │ └── UsersTableSeeder.php ├── jsconfig.json ├── lang ├── en │ ├── auth.php │ ├── frontend.php │ ├── pagination.php │ ├── passwords.php │ └── validation.php └── mk │ └── frontend.php ├── package-lock.json ├── package.json ├── phpunit.xml ├── postcss.config.js ├── public ├── .htaccess ├── assets │ └── images │ │ ├── login.jpg │ │ └── logo.png ├── favicon.ico ├── index.php ├── mix-manifest.json ├── robots.txt └── web.config ├── resources ├── app │ ├── App.vue │ ├── helpers │ │ ├── alert.js │ │ ├── api.js │ │ ├── data.js │ │ ├── i18n.js │ │ └── routing.js │ ├── main.js │ ├── plugins │ │ ├── axios.js │ │ └── i18n.js │ ├── router │ │ ├── index.js │ │ └── routes.js │ ├── services │ │ ├── AuthService.ts │ │ ├── BaseService.ts │ │ ├── ModelService.ts │ │ ├── SearchService.ts │ │ └── UserService.ts │ ├── stores │ │ ├── alert.js │ │ ├── auth.js │ │ ├── global.js │ │ └── index.js │ ├── stub │ │ └── abilities.js │ └── views │ │ ├── components │ │ ├── Alert.vue │ │ ├── Badge.vue │ │ ├── Form.vue │ │ ├── Modal.vue │ │ ├── Pager.vue │ │ ├── Panel.vue │ │ ├── Table.vue │ │ ├── filters │ │ │ ├── Filters.vue │ │ │ ├── FiltersCol.vue │ │ │ └── FiltersRow.vue │ │ ├── icons │ │ │ ├── Avatar.vue │ │ │ ├── Icon.vue │ │ │ └── Spinner.vue │ │ └── input │ │ │ ├── Button.vue │ │ │ ├── Dropdown.vue │ │ │ ├── FileInput.vue │ │ │ └── TextInput.vue │ │ ├── layouts │ │ ├── Auth.vue │ │ ├── Menu.vue │ │ └── Page.vue │ │ └── pages │ │ ├── auth │ │ ├── forgot-password │ │ │ ├── Form.vue │ │ │ └── Main.vue │ │ ├── login │ │ │ ├── Form.vue │ │ │ └── Main.vue │ │ ├── register │ │ │ ├── Form.vue │ │ │ └── Main.vue │ │ └── reset-password │ │ │ ├── Form.vue │ │ │ └── Main.vue │ │ ├── private │ │ ├── dashboard │ │ │ └── Main.vue │ │ ├── profile │ │ │ ├── Main.vue │ │ │ └── partials │ │ │ │ ├── FormAvatar.vue │ │ │ │ ├── FormGeneral.vue │ │ │ │ ├── FormPassword.vue │ │ │ │ └── Overview.vue │ │ └── users │ │ │ ├── Create.vue │ │ │ ├── Edit.vue │ │ │ └── Index.vue │ │ └── shared │ │ └── 404 │ │ └── Main.vue ├── styles │ ├── main.scss │ └── tailwind.scss └── views │ └── index.blade.php ├── routes ├── api.php ├── console.php └── web.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ ├── .gitignore │ │ └── data │ │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tailwind.config.js ├── tests ├── Feature │ └── ExampleTest.php ├── TestCase.php └── Unit │ └── ExampleTest.php ├── tsconfig.json └── vite.config.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | 17 | [docker-compose.yml] 18 | indent_size = 4 19 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_TIMEZONE=UTC 6 | APP_URL=http://localhost 7 | 8 | APP_LOCALE=en 9 | APP_FALLBACK_LOCALE=en 10 | APP_FAKER_LOCALE=en_US 11 | 12 | APP_MAINTENANCE_DRIVER=file 13 | APP_MAINTENANCE_STORE=database 14 | 15 | BCRYPT_ROUNDS=12 16 | 17 | LOG_CHANNEL=stack 18 | LOG_STACK=single 19 | LOG_DEPRECATIONS_CHANNEL=null 20 | LOG_LEVEL=debug 21 | 22 | DB_CONNECTION=sqlite 23 | # DB_HOST=127.0.0.1 24 | # DB_PORT=3306 25 | # DB_DATABASE=laravel 26 | # DB_USERNAME=root 27 | # DB_PASSWORD= 28 | 29 | SESSION_DRIVER=database 30 | SESSION_LIFETIME=120 31 | SESSION_ENCRYPT=false 32 | SESSION_PATH=/ 33 | SESSION_DOMAIN=null 34 | 35 | BROADCAST_CONNECTION=log 36 | FILESYSTEM_DISK=local 37 | QUEUE_CONNECTION=database 38 | 39 | CACHE_STORE=database 40 | CACHE_PREFIX= 41 | 42 | MEMCACHED_HOST=127.0.0.1 43 | 44 | REDIS_CLIENT=phpredis 45 | REDIS_HOST=127.0.0.1 46 | REDIS_PASSWORD=null 47 | REDIS_PORT=6379 48 | 49 | MAIL_MAILER=log 50 | MAIL_HOST=127.0.0.1 51 | MAIL_PORT=2525 52 | MAIL_USERNAME=null 53 | MAIL_PASSWORD=null 54 | MAIL_ENCRYPTION=null 55 | MAIL_FROM_ADDRESS="hello@example.com" 56 | MAIL_FROM_NAME="${APP_NAME}" 57 | 58 | AWS_ACCESS_KEY_ID= 59 | AWS_SECRET_ACCESS_KEY= 60 | AWS_DEFAULT_REGION=us-east-1 61 | AWS_BUCKET= 62 | AWS_USE_PATH_STYLE_ENDPOINT=false 63 | 64 | VITE_APP_NAME="${APP_NAME}" 65 | 66 | # Customizations 67 | SANCTUM_STATEFUL_DOMAINS=yourdomain.test 68 | SESSION_DOMAIN=yourdomain.test 69 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.blade.php diff=html 4 | *.css diff=css 5 | *.html diff=html 6 | *.md diff=markdown 7 | *.php diff=php 8 | 9 | /.github export-ignore 10 | CHANGELOG.md export-ignore 11 | .styleci.yml export-ignore 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.phpunit.cache 2 | /node_modules 3 | /public/build 4 | /public/hot 5 | /public/storage 6 | /storage/*.key 7 | /vendor 8 | .env 9 | .env.backup 10 | .env.production 11 | .phpactor.json 12 | .phpunit.result.cache 13 | Homestead.json 14 | Homestead.yaml 15 | auth.json 16 | npm-debug.log 17 | yarn-error.log 18 | /.fleet 19 | /.idea 20 | /.vscode 21 | 22 | /public/css/* 23 | /public/js/* 24 | composer.lock 25 | composer.phar 26 | 27 | .phpstorm.meta.php 28 | _ide_helper.php 29 | _ide_helper_models.php 30 | -------------------------------------------------------------------------------- /app/Actions/Fortify/CreateNewUser.php: -------------------------------------------------------------------------------- 1 | ['required', 'string', 'max:100'], 24 | 'last_name' => ['required', 'string', 'max:100'], 25 | 'email' => [ 26 | 'required', 27 | 'string', 28 | 'email', 29 | 'max:255', 30 | Rule::unique(User::class), 31 | ], 32 | 'password' => $this->passwordRules(), 33 | ])->validate(); 34 | 35 | return User::create([ 36 | 'first_name' => $input['first_name'], 37 | 'last_name' => $input['last_name'], 38 | 'email' => $input['email'], 39 | 'password' => Hash::make($input['password']), 40 | ]); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/Actions/Fortify/PasswordValidationRules.php: -------------------------------------------------------------------------------- 1 | $this->passwordRules(), 23 | ])->validate(); 24 | 25 | $user->forceFill([ 26 | 'password' => Hash::make($input['password']), 27 | ])->save(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Actions/Fortify/UpdateUserPassword.php: -------------------------------------------------------------------------------- 1 | ['required', 'string'], 23 | 'password' => $this->passwordRules(), 24 | ])->after(function ($validator) use ($user, $input) { 25 | if (! isset($input['current_password']) || ! Hash::check($input['current_password'], $user->password)) { 26 | $validator->errors()->add('current_password', __('The provided password does not match your current password.')); 27 | } 28 | })->validateWithBag('updatePassword'); 29 | 30 | $user->forceFill([ 31 | 'password' => Hash::make($input['password']), 32 | ])->save(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Actions/Fortify/UpdateUserProfileInformation.php: -------------------------------------------------------------------------------- 1 | ['required', 'string', 'max:100'], 22 | 'last_name' => ['required', 'string', 'max:100'], 23 | 'middle_name' => ['nullable', 'string', 'max:100'], 24 | 25 | 'email' => [ 26 | 'required', 27 | 'string', 28 | 'email', 29 | 'max:255', 30 | Rule::unique('users')->ignore($user->id), 31 | ], 32 | ])->validateWithBag('updateProfileInformation'); 33 | 34 | if ($input['email'] !== $user->email && 35 | $user instanceof MustVerifyEmail) { 36 | $this->updateVerifiedUser($user, $input); 37 | } else { 38 | $user->forceFill([ 39 | 'first_name' => $input['first_name'], 40 | 'last_name' => $input['last_name'], 41 | 'middle_name' => $input['middle_name'] ?? null, 42 | 'email' => $input['email'], 43 | ])->save(); 44 | } 45 | } 46 | 47 | /** 48 | * Update the given verified user's profile information. 49 | * 50 | * @param mixed $user 51 | * @return void 52 | */ 53 | protected function updateVerifiedUser($user, array $input) 54 | { 55 | $user->forceFill([ 56 | 'first_name' => $input['first_name'], 57 | 'last_name' => $input['last_name'], 58 | 'email' => $input['email'], 59 | 'email_verified_at' => null, 60 | ])->save(); 61 | 62 | $user->sendEmailVerificationNotification(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/Http/Controllers/AuthController.php: -------------------------------------------------------------------------------- 1 | responseSuccess('', $data); 35 | } 36 | 37 | /** 38 | * Send a successful response 39 | * 40 | * @return \Illuminate\Http\JsonResponse 41 | */ 42 | protected function responseDeleteSuccess($data = [], $code = 200) 43 | { 44 | return $this->responseSuccess(trans('frontend.global.phrases.record_deleted'), $data, $code); 45 | } 46 | 47 | /** 48 | * Send a failed response 49 | * 50 | * @return \Illuminate\Http\JsonResponse 51 | */ 52 | protected function responseDeleteFail(array $data = [], int $code = 422) 53 | { 54 | return $this->responseFail(trans('frontend.global.phrases.record_not_deleted'), $data, $code); 55 | } 56 | 57 | /** 58 | * Send a successful response 59 | * 60 | * @return \Illuminate\Http\JsonResponse 61 | */ 62 | protected function responseUpdateSuccess($data = [], $code = 200) 63 | { 64 | return $this->responseSuccess(trans('frontend.global.phrases.record_updated'), $data, $code); 65 | } 66 | 67 | /** 68 | * Send a failed response 69 | * 70 | * @return \Illuminate\Http\JsonResponse 71 | */ 72 | protected function responseUpdateFail(array $data = [], int $code = 422) 73 | { 74 | return $this->responseFail(trans('frontend.global.phrases.record_not_updated'), $data, $code); 75 | } 76 | 77 | /** 78 | * Send a successful response 79 | * 80 | * @return \Illuminate\Http\JsonResponse 81 | */ 82 | protected function responseStoreSuccess($data = [], $code = 200) 83 | { 84 | return $this->responseSuccess(trans('frontend.global.phrases.record_created'), $data, $code); 85 | } 86 | 87 | /** 88 | * Send a failed response 89 | * 90 | * @return \Illuminate\Http\JsonResponse 91 | */ 92 | protected function responseStoreFail(array $data = [], int $code = 422) 93 | { 94 | return $this->responseFail(trans('frontend.global.phrases.record_not_created'), $data, $code); 95 | } 96 | 97 | /** 98 | * Send a successful response 99 | * 100 | * @return JsonResponse 101 | */ 102 | protected function responseSuccess(string $message, array $data = [], int $code = 200) 103 | { 104 | return $this->response($code, $message, $data); 105 | } 106 | 107 | /** 108 | * Send a failed response 109 | * 110 | * @return \Illuminate\Http\JsonResponse 111 | */ 112 | protected function responseFail(string $message, array $data = [], int $code = 400) 113 | { 114 | return $this->response($code, $message, $data); 115 | } 116 | 117 | /** 118 | * Returns a response 119 | * 120 | * @return JsonResponse 121 | */ 122 | protected function response(int $code, string $message = '', array $data = []) 123 | { 124 | return response()->json(array_merge(['message' => $message], $data), $code); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/Http/Controllers/RoleController.php: -------------------------------------------------------------------------------- 1 | roleService = $service; 25 | } 26 | 27 | /** 28 | * Handle search data 29 | * 30 | * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection 31 | * 32 | * @throws AuthorizationException 33 | */ 34 | public function search(Request $request) 35 | { 36 | $this->authorize('search', Role::class); 37 | 38 | return $this->roleService->index($request->all()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/Http/Controllers/SpaController.php: -------------------------------------------------------------------------------- 1 | validate([ 20 | 'email' => 'required|email', 21 | 'password' => 'required', 22 | 'device_name' => 'required', 23 | ]); 24 | 25 | $user = User::where('email', $request->email)->first(); 26 | 27 | if (! $user || ! Hash::check($request->password, $user->password)) { 28 | throw ValidationException::withMessages([ 29 | 'email' => ['The provided credentials are incorrect.'], 30 | ]); 31 | } 32 | 33 | $token = $user->createToken($request->device_name)->plainTextToken; 34 | 35 | return response()->json(['token' => $token], 200); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Http/Controllers/UserController.php: -------------------------------------------------------------------------------- 1 | userService = $userService; 29 | } 30 | 31 | /** 32 | * Display a listing of the resource. 33 | * 34 | * @return JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection 35 | * 36 | * @throws AuthorizationException 37 | */ 38 | public function index(Request $request) 39 | { 40 | $this->authorize('list', User::class); 41 | 42 | return $this->userService->index($request->all()); 43 | } 44 | 45 | /** 46 | * Show the form for creating a new resource. 47 | * 48 | * @return JsonResponse|\Illuminate\Http\Response 49 | * 50 | * @throws AuthorizationException 51 | */ 52 | public function create() 53 | { 54 | $this->authorize('create', User::class); 55 | 56 | return $this->responseDataSuccess(['properties' => $this->properties()]); 57 | } 58 | 59 | /** 60 | * Store a newly created resource in storage. 61 | * 62 | * 63 | * @return JsonResponse 64 | * 65 | * @throws AuthorizationException 66 | */ 67 | public function store(StoreUserRequest $request) 68 | { 69 | $this->authorize('create', User::class); 70 | 71 | $input = $request->validated(); 72 | $record = $this->userService->create($input); 73 | if (! is_null($record)) { 74 | return $this->responseStoreSuccess(['record' => $record]); 75 | } else { 76 | return $this->responseStoreFail(); 77 | } 78 | } 79 | 80 | /** 81 | * Show the form for editing the specified resource. 82 | * 83 | * 84 | * @return UserResource|JsonResponse 85 | * 86 | * @throws AuthorizationException 87 | */ 88 | public function show(User $user) 89 | { 90 | $this->authorize('view', User::class); 91 | 92 | $model = $this->userService->get($user); 93 | 94 | return $this->responseDataSuccess(['model' => $model, 'properties' => $this->properties()]); 95 | } 96 | 97 | /** 98 | * Show the form for editing the specified resource. 99 | * 100 | * 101 | * @return JsonResponse|\Illuminate\Http\Response 102 | * 103 | * @throws AuthorizationException 104 | */ 105 | public function edit(User $user) 106 | { 107 | $this->authorize('edit', User::class); 108 | 109 | return $this->show($user); 110 | } 111 | 112 | /** 113 | * Update the specified resource in storage. 114 | * 115 | * 116 | * @return JsonResponse 117 | * 118 | * @throws AuthorizationException 119 | */ 120 | public function update(UpdateUserRequest $request, User $user) 121 | { 122 | $this->authorize('edit', User::class); 123 | 124 | $data = $request->validated(); 125 | if ($this->userService->update($user, $data)) { 126 | return $this->responseUpdateSuccess(['record' => $user->fresh()]); 127 | } else { 128 | return $this->responseUpdateFail(); 129 | } 130 | } 131 | 132 | /** 133 | * Update avatar in for specified user 134 | * 135 | * @return JsonResponse 136 | * 137 | * @throws AuthorizationException 138 | */ 139 | public function updateAvatar(UpdateAvatarRequest $request, User $user) 140 | { 141 | $this->authorize('edit-profile', User::class); 142 | 143 | $data = $request->validated(); 144 | if ($this->userService->updateAvatar($user, $data)) { 145 | return $this->responseUpdateSuccess(['record' => $user->fresh()]); 146 | } else { 147 | return $this->responseUpdateFail(); 148 | } 149 | } 150 | 151 | /** 152 | * Remove the specified resource from storage. 153 | * 154 | * @param int $id 155 | * @return JsonResponse 156 | * 157 | * @throws AuthorizationException 158 | */ 159 | public function destroy(DestroyUserRequest $request, User $user) 160 | { 161 | $this->authorize('delete', User::class); 162 | 163 | if ($this->userService->delete($user)) { 164 | return $this->responseDeleteSuccess(['record' => $user]); 165 | } 166 | 167 | return $this->responseDeleteFail(); 168 | 169 | } 170 | 171 | /** 172 | * Render properties 173 | * 174 | * @return array 175 | */ 176 | public function properties() 177 | { 178 | return []; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /app/Http/Middleware/ApplyLocale.php: -------------------------------------------------------------------------------- 1 | header('X-Locale'); 19 | if (! empty($locale)) { 20 | app()->setLocale($locale); 21 | } 22 | 23 | return $next($request); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/Http/Middleware/RedirectIfAuthenticated.php: -------------------------------------------------------------------------------- 1 | check()) { 26 | if ($request->expectsJson()) { 27 | return response()->json(['message' => 'Already authenticated.'], 200); 28 | } 29 | 30 | return redirect(AppServiceProvider::HOME); 31 | } 32 | } 33 | 34 | return $next($request); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/Http/Requests/BaseRequest.php: -------------------------------------------------------------------------------- 1 | 'required|string|max:100', 14 | 'last_name' => 'required|string|max:100', 15 | 'middle_name' => 'nullable|string|max:100', 16 | 'email' => 'required|email|unique:users', 17 | 'roles' => 'required|array|exists:roles,name', 18 | 'avatar' => $this->request->has('avatar') ? 'nullable' : 'image', 19 | 'password' => 'required|min:6', 20 | ]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/Http/Requests/UpdateAvatarRequest.php: -------------------------------------------------------------------------------- 1 | 'required|image', 11 | ]; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/Http/Requests/UpdateUserRequest.php: -------------------------------------------------------------------------------- 1 | 'required|string|max:100', 14 | 'last_name' => 'required|string|max:100', 15 | 'middle_name' => 'nullable|string|max:100', 16 | 'email' => 'required|email|unique:users,email,'.$this->request->get('email').',email|max:200', 17 | 'roles' => 'required|array|exists:roles,name', 18 | 'avatar' => 'nullable|image', 19 | 'password' => 'nullable|min:6', 20 | ]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/Http/Resources/RoleResource.php: -------------------------------------------------------------------------------- 1 | resource->toArray(); 17 | 18 | return ['id' => $data['name'], 'title' => $data['title']]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Http/Resources/UserBasicResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 18 | 'name' => $this->first_name.' '.$this->last_name, 19 | 'email' => $this->email, 20 | ]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/Http/Resources/UserResource.php: -------------------------------------------------------------------------------- 1 | resource->toArray(); 22 | $data['is_admin'] = $this->is_admin; 23 | $data['is_owner'] = \Auth::check() && \Auth::user()->id === $this->id; 24 | $data['abilities'] = $this->getAbilities(); 25 | $data['created_at'] = ! empty($this->resource->created_at) ? $this->resource->created_at->diffForHumans() : null; 26 | $data['updated_at'] = ! empty($this->resource->updated_at) ? $this->resource->updated_at->diffForHumans() : null; 27 | $data['roles'] = Data::formatCollectionForSelect($this->roles, 'name', 'trans'); 28 | if (isset($data['avatar'])) { 29 | unset($data['avatar']); 30 | } 31 | 32 | return $data; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Http/Responses/LoginResponse.php: -------------------------------------------------------------------------------- 1 | wantsJson() 17 | ? response()->json(['user' => Auth::user()]) 18 | : redirect()->intended(Fortify::redirects('login')); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Models/Role.php: -------------------------------------------------------------------------------- 1 | |bool 36 | */ 37 | protected $guarded = ['id']; 38 | 39 | /** 40 | * The attributes that should be hidden for serialization. 41 | * 42 | * @var array 43 | */ 44 | protected $hidden = [ 45 | 'password', 46 | 'remember_token', 47 | ]; 48 | 49 | /** 50 | * The accessors to append to the model's array form. 51 | * 52 | * @var array 53 | */ 54 | protected $appends = [ 55 | 'avatar_url', 56 | 'avatar_thumb_url', 57 | 'full_name', 58 | ]; 59 | 60 | /** 61 | * Bootstrap the model and its traits. 62 | * 63 | * @return void 64 | */ 65 | public static function boot() 66 | { 67 | parent::boot(); 68 | } 69 | 70 | /** 71 | * Get the attributes that should be cast. 72 | * 73 | * @return array 74 | */ 75 | protected function casts(): array 76 | { 77 | return [ 78 | 'email_verified_at' => 'datetime', 79 | ]; 80 | } 81 | 82 | /** 83 | * @return \Closure|mixed|null|Media 84 | */ 85 | public function avatar() 86 | { 87 | return $this->getMedia('avatars')->first(); 88 | } 89 | 90 | /** 91 | * Returns the avatar url attribute 92 | * 93 | * @return string|null 94 | */ 95 | public function getAvatarUrlAttribute() 96 | { 97 | $avatar = $this->avatar(); 98 | if ($avatar) { 99 | return $avatar->getFullUrl(); 100 | } 101 | 102 | return null; 103 | } 104 | 105 | /** 106 | * Returns the avatar url attribute 107 | * 108 | * @return string|null 109 | */ 110 | public function getAvatarThumbUrlAttribute() 111 | { 112 | $avatar = $this->avatar(); 113 | if ($avatar) { 114 | return $avatar->getAvailableFullUrl(['small_thumb']); 115 | } 116 | 117 | return null; 118 | } 119 | 120 | /** 121 | * Returns the full_name attribute 122 | * 123 | * @return string 124 | */ 125 | public function getFullNameAttribute() 126 | { 127 | $names = []; 128 | foreach (['first_name', 'middle_name', 'last_name'] as $key) { 129 | $value = $this->getAttribute($key); 130 | if (! empty($value)) { 131 | $names[] = $value; 132 | } 133 | } 134 | 135 | return implode(' ', $names); 136 | } 137 | 138 | /** 139 | * Returns the is_admin attribute 140 | * 141 | * @return bool 142 | */ 143 | public function getIsAdminAttribute() 144 | { 145 | return $this->isAn('admin'); 146 | } 147 | 148 | /** 149 | * Register the conversions 150 | * 151 | * 152 | * @throws \Spatie\Image\Exceptions\InvalidManipulation 153 | */ 154 | public function registerMediaConversions(?Media $media = null): void 155 | { 156 | $this->addMediaConversion('small_thumb') 157 | ->fit(Manipulations::FIT_CROP, 300, 300) 158 | ->nonQueued(); 159 | $this->addMediaConversion('medium_thumb') 160 | ->fit(Manipulations::FIT_CROP, 600, 600) 161 | ->nonQueued(); 162 | $this->addMediaConversion('large_thumb') 163 | ->fit(Manipulations::FIT_CROP, 1200, 1200) 164 | ->nonQueued(); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | bootAuth(); 39 | $this->bootRoute(); 40 | } 41 | 42 | public function bootAuth() 43 | { 44 | ResetPassword::createUrlUsing(function ($user, string $token) { 45 | return env('APP_URL').'/reset-password?token='.$token; 46 | }); 47 | } 48 | 49 | public function bootRoute() 50 | { 51 | RateLimiter::for('login', function (Request $request) { 52 | return Limit::perMinute(10); 53 | }); 54 | RateLimiter::for('api', function (Request $request) { 55 | return Limit::perMinute(30); 56 | }); 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/Providers/FortifyServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->instance(LoginResponseContract::class, new LoginResponse()); 22 | } 23 | 24 | /** 25 | * Bootstrap any application services. 26 | */ 27 | public function boot(): void 28 | { 29 | Fortify::createUsersUsing(CreateNewUser::class); 30 | Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class); 31 | Fortify::updateUserPasswordsUsing(UpdateUserPassword::class); 32 | Fortify::resetUserPasswordsUsing(ResetUserPassword::class); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Services/Media/MediaService.php: -------------------------------------------------------------------------------- 1 | getMedia($collection); 26 | foreach ($media as $media_item) { 27 | $media_item->delete(); 28 | } 29 | 30 | return $this->store($file, $user, $collection); 31 | } 32 | 33 | /** 34 | * Handles a file upload to the storage 35 | * 36 | * 37 | * @return Media 38 | * 39 | * @throws FileDoesNotExist 40 | * @throws FileIsTooBig 41 | */ 42 | public function store(UploadedFile $file, User $user, $collection) 43 | { 44 | return $user->addMedia($file)->toMediaCollection($collection); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/Services/Role/RoleService.php: -------------------------------------------------------------------------------- 1 | search($data['search']); 23 | } 24 | if (! empty($data['sort_by']) && ! empty($data['sort'])) { 25 | $query = $query->orderBy($data['sort_by'], $data['sort']); 26 | } 27 | 28 | return RoleResource::collection($query->paginate($per_page)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Services/User/UserService.php: -------------------------------------------------------------------------------- 1 | mediaService = new MediaService(); 33 | } 34 | 35 | /** 36 | * Get a single resource from the database 37 | * 38 | * 39 | * @return UserResource 40 | */ 41 | public function get(User $user) 42 | { 43 | return new UserResource($user); 44 | } 45 | 46 | /** 47 | * Get resource index from the database 48 | * 49 | * @param $query 50 | * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection 51 | */ 52 | public function index($data) 53 | { 54 | $query = User::query(); 55 | if (! empty($data['search'])) { 56 | $query = $query->search($data['search']); 57 | } 58 | if (! empty($data['filters'])) { 59 | $this->filter($query, $data['filters']); 60 | } 61 | if (! empty($data['sort_by']) && ! empty($data['sort'])) { 62 | $query = $query->orderBy($data['sort_by'], $data['sort']); 63 | } 64 | 65 | return UserResource::collection($query->paginate(10)); 66 | } 67 | 68 | /** 69 | * Creates resource in the database 70 | * 71 | * 72 | * @return Builder|Model|null 73 | * 74 | * @throws FileDoesNotExist 75 | * @throws FileIsTooBig 76 | */ 77 | public function create(array $data) 78 | { 79 | $data = $this->clean($data); 80 | 81 | if (isset($data['password'])) { 82 | $data['password'] = bcrypt($data['password']); 83 | } 84 | 85 | $data['email_verified_at'] = Carbon::now()->toDateTimeString(); 86 | $roles = Data::take($data, 'roles'); 87 | $avatar = Data::take($data, 'avatar'); 88 | 89 | $record = User::query()->create($data); 90 | if (! empty($record)) { 91 | // Set avatar 92 | if (! empty($avatar)) { 93 | $this->mediaService->replace($avatar, $record, 'avatars'); 94 | } 95 | // Set roles 96 | if (! empty($roles)) { 97 | Bouncer::sync($record)->roles($roles); 98 | } 99 | 100 | return $record->fresh(); 101 | } else { 102 | return null; 103 | } 104 | } 105 | 106 | /** 107 | * Updates resource in the database 108 | * 109 | * 110 | * @return bool 111 | * 112 | * @throws FileDoesNotExist 113 | * @throws FileIsTooBig 114 | */ 115 | public function update(User $user, array $data) 116 | { 117 | $data = $this->clean($data); 118 | 119 | if (empty($data['password'])) { 120 | unset($data['password']); 121 | } else { 122 | $data['password'] = bcrypt($data['password']); 123 | } 124 | 125 | $roles = Data::take($data, 'roles'); 126 | 127 | unset($data['email']); 128 | 129 | if (isset($data['avatar']) && $data['avatar']) { 130 | $this->mediaService->replace($data['avatar'], $user, 'avatars'); 131 | } 132 | 133 | if (! empty($roles)) { 134 | Bouncer::sync($user)->roles($roles); 135 | } 136 | 137 | return $user->update($data); 138 | } 139 | 140 | /** 141 | * Update avatar for the specified resource 142 | * 143 | * 144 | * @return bool 145 | */ 146 | public function updateAvatar(User $user, array $data) 147 | { 148 | if (isset($data['avatar']) && $data['avatar']) { 149 | $this->mediaService->replace($data['avatar'], $user, 'avatars'); 150 | } 151 | if (! empty($data)) { 152 | return $user->update($data); 153 | } else { 154 | return false; 155 | } 156 | } 157 | 158 | /** 159 | * Deletes resource in the database 160 | * 161 | * @param User|Model $user 162 | * @return bool 163 | */ 164 | public function delete(User $user) 165 | { 166 | return $user->delete(); 167 | } 168 | 169 | /** 170 | * Clean the data 171 | * 172 | * 173 | * @return array 174 | */ 175 | private function clean(array $data) 176 | { 177 | foreach ($data as $i => $row) { 178 | if ($row === 'null') { 179 | $data[$i] = null; 180 | } 181 | } 182 | 183 | return $data; 184 | } 185 | 186 | /** 187 | * Filter resources 188 | * 189 | * @return void 190 | */ 191 | private function filter(Builder &$query, $filters) 192 | { 193 | $query->filter(Arr::except($filters, ['role'])); 194 | 195 | if (! empty($filters['role'])) { 196 | $roleFilter = Filterable::parseFilter($filters['role']); 197 | if (! empty($roleFilter)) { 198 | if (is_array($roleFilter[2])) { 199 | $query->whereIs(...$roleFilter[2]); 200 | } else { 201 | $query->whereIs($roleFilter[2]); 202 | } 203 | } 204 | } 205 | 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /app/Traits/Filterable.php: -------------------------------------------------------------------------------- 1 | 'where', 19 | 'AND_WHERE_IN' => 'whereIn', 20 | 'OR_WHERE' => 'orWhere', 21 | 'OR_WHERE_IN' => 'orWhereIn', 22 | ]; 23 | foreach ($data as $column => $value) { 24 | $filterParts = self::parseFilter($value); 25 | if (empty($filterParts)) { 26 | continue; 27 | } 28 | $comparison = $filterParts[1]; 29 | $inputVal = $filterParts[2]; 30 | if (is_array($inputVal)) { 31 | call_user_func_array([$query, $callbacks[$operator.'_WHERE_IN']], [$column, $inputVal]); 32 | } else { 33 | if (! is_numeric($inputVal)) { 34 | $comparison = 'LIKE'; 35 | $inputVal = '%'.$inputVal.'%'; 36 | } 37 | call_user_func_array([$query, $callbacks[$operator.'_WHERE']], [$column, $comparison, $inputVal]); 38 | } 39 | } 40 | 41 | return $query; 42 | } 43 | 44 | /** 45 | * Parse the filter 46 | * 47 | * @return array|string|string[] 48 | */ 49 | public static function parseFilter($value) 50 | { 51 | $filterParts = explode(';', $value); 52 | $totalFilterParts = count($filterParts); 53 | if ($totalFilterParts !== 3) { 54 | return []; 55 | } 56 | $value = $filterParts[$totalFilterParts - 1]; 57 | if (strpos($value, '|') !== false) { 58 | $filterParts[$totalFilterParts - 1] = explode('|', $value); 59 | } 60 | 61 | return $filterParts; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/Traits/Searchable.php: -------------------------------------------------------------------------------- 1 | where($field, 'LIKE', "%$keyword%"); 23 | } else { 24 | $query->orWhere($field, 'LIKE', "%$keyword%"); 25 | } 26 | } 27 | 28 | }); 29 | } 30 | 31 | /** 32 | * Get all searchable fields 33 | * 34 | * @return array 35 | */ 36 | public static function getSearchableFields() 37 | { 38 | /** 39 | * @var Model $model 40 | */ 41 | $model = new static; 42 | 43 | $fields = $model->searchFields; 44 | 45 | if (empty($fields)) { 46 | $fields = Schema::getColumnListing($model->getTable()); 47 | 48 | $ignoredColumns = [ 49 | $model->getKeyName(), 50 | $model->getUpdatedAtColumn(), 51 | $model->getCreatedAtColumn(), 52 | ]; 53 | 54 | if (method_exists($model, 'getDeletedAtColumn')) { 55 | $ignoredColumns[] = $model->getDeletedAtColumn(); 56 | } 57 | 58 | $fields = array_diff($fields, $model->getHidden(), $ignoredColumns); 59 | } 60 | 61 | return $fields; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/Utilities/Data.php: -------------------------------------------------------------------------------- 1 | map(function ($entry) use ($value, $label) { 17 | $id = $entry->$value ?? null; 18 | $label = $label === 'trans' ? trans('frontend.users.roles.'.$id) : ($entry->$label ?? $entry->$id); 19 | 20 | return [ 21 | 'id' => $id, 22 | 'title' => $label, 23 | ]; 24 | }); 25 | } 26 | 27 | /** 28 | * Take value form array 29 | * 30 | * @return mixed|null 31 | */ 32 | public static function take(&$arr, $key) 33 | { 34 | if (isset($arr[$key])) { 35 | $value = $arr[$key]; 36 | unset($arr[$key]); 37 | 38 | return $value; 39 | } 40 | 41 | return null; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | handleCommand(new ArgvInput); 14 | 15 | exit($status); 16 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | withProviders() 9 | ->withRouting( 10 | web: __DIR__.'/../routes/web.php', 11 | api: __DIR__.'/../routes/api.php', 12 | commands: __DIR__.'/../routes/console.php', 13 | // channels: __DIR__.'/../routes/channels.php', 14 | health: '/up', 15 | ) 16 | ->withMiddleware(function (Middleware $middleware) { 17 | $middleware->redirectGuestsTo(fn () => url(env('APP_URL').'/login')); 18 | 19 | $middleware->statefulApi(); 20 | $middleware->throttleApi(); 21 | 22 | $middleware->alias([ 23 | 'apply_locale' => \App\Http\Middleware\ApplyLocale::class, 24 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 25 | ]); 26 | }) 27 | ->withExceptions(function (Exceptions $exceptions) { 28 | // 29 | })->create(); 30 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /bootstrap/providers.php: -------------------------------------------------------------------------------- 1 | [ 6 | 'api/*', 7 | 'login', 8 | 'logout', 9 | 'register', 10 | 'user/password', 11 | 'forgot-password', 12 | 'reset-password', 13 | 'sanctum/csrf-cookie', 14 | 'user/profile-information', 15 | 'email/verification-notification', 16 | ], 17 | 18 | 'supports_credentials' => true, 19 | 20 | ]; 21 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | [ 6 | 'table' => 'migrations', 7 | 'update_date_on_publish' => false, // disable to preserve original behavior for existing applications 8 | ], 9 | 10 | ]; 11 | -------------------------------------------------------------------------------- /config/fortify.php: -------------------------------------------------------------------------------- 1 | 'web', 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Fortify Password Broker 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may specify which password broker Fortify can use when a user 27 | | is resetting their password. This configured value should match one 28 | | of your password brokers setup in your "auth" configuration file. 29 | | 30 | */ 31 | 32 | 'passwords' => 'users', 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | Username / Email 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This value defines which model attribute should be considered as your 40 | | application's "username" field. Typically, this might be the email 41 | | address of the users but you are free to change this value here. 42 | | 43 | | Out of the box, Fortify expects forgot password and reset password 44 | | requests to have a field named 'email'. If the application uses 45 | | another name for the field you may define it below as needed. 46 | | 47 | */ 48 | 49 | 'username' => 'email', 50 | 51 | 'email' => 'email', 52 | 53 | /* 54 | |-------------------------------------------------------------------------- 55 | | Home Path 56 | |-------------------------------------------------------------------------- 57 | | 58 | | Here you may configure the path where users will get redirected during 59 | | authentication or password reset when the operations are successful 60 | | and the user is authenticated. You are free to change this value. 61 | | 62 | */ 63 | 64 | //'home' => AppServiceProvider::HOME, 65 | 'home' => env('APP_URL').'/panel/dashboard', 66 | 67 | /* 68 | |-------------------------------------------------------------------------- 69 | | Fortify Routes Prefix / Subdomain 70 | |-------------------------------------------------------------------------- 71 | | 72 | | Here you may specify which prefix Fortify will assign to all the routes 73 | | that it registers with the application. If necessary, you may change 74 | | subdomain under which all of the Fortify routes will be available. 75 | | 76 | */ 77 | 78 | 'prefix' => '', 79 | 80 | 'domain' => null, 81 | 82 | /* 83 | |-------------------------------------------------------------------------- 84 | | Fortify Routes Middleware 85 | |-------------------------------------------------------------------------- 86 | | 87 | | Here you may specify which middleware Fortify will assign to the routes 88 | | that it registers with the application. If necessary, you may change 89 | | these middleware but typically this provided default is preferred. 90 | | 91 | */ 92 | 93 | 'middleware' => ['web'], 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Rate Limiting 98 | |-------------------------------------------------------------------------- 99 | | 100 | | By default, Fortify will throttle logins to five requests per minute for 101 | | every email and IP address combination. However, if you would like to 102 | | specify a custom rate limiter to call then you may specify it here. 103 | | 104 | */ 105 | 106 | 'limiters' => [ 107 | 'login' => 'login', 108 | 'two-factor' => 'two-factor', 109 | ], 110 | 111 | /* 112 | |-------------------------------------------------------------------------- 113 | | Register View Routes 114 | |-------------------------------------------------------------------------- 115 | | 116 | | Here you may specify if the routes returning views should be disabled as 117 | | you may not need them when building your own application. This may be 118 | | especially true if you're writing a custom single-page application. 119 | | 120 | */ 121 | 122 | 'views' => false, 123 | 124 | /* 125 | |-------------------------------------------------------------------------- 126 | | Features 127 | |-------------------------------------------------------------------------- 128 | | 129 | | Some of the Fortify features are optional. You may disable the features 130 | | by removing them from this array. You're free to only remove some of 131 | | these features or you can even remove all of these if you need to. 132 | | 133 | */ 134 | 135 | 'features' => [ 136 | Features::registration(), 137 | Features::resetPasswords(), 138 | Features::emailVerification(), 139 | Features::updateProfileInformation(), 140 | Features::updatePasswords(), 141 | //Features::twoFactorAuthentication([ 142 | // 'confirm' => true, 143 | // 'confirmPassword' => true, 144 | // 'window' => 0, 145 | //]), 146 | ], 147 | 148 | ]; 149 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | [ 6 | 'mailgun' => [ 7 | 'transport' => 'mailgun', 8 | ], 9 | ], 10 | 11 | ]; 12 | -------------------------------------------------------------------------------- /config/sanctum.php: -------------------------------------------------------------------------------- 1 | explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( 19 | '%s%s', 20 | 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', 21 | Sanctum::currentApplicationUrlWithPort() 22 | ))), 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Sanctum Guards 27 | |-------------------------------------------------------------------------- 28 | | 29 | | This array contains the authentication guards that will be checked when 30 | | Sanctum is trying to authenticate a request. If none of these guards 31 | | are able to authenticate the request, Sanctum will use the bearer 32 | | token that's present on an incoming request for authentication. 33 | | 34 | */ 35 | 36 | 'guard' => ['web'], 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Expiration Minutes 41 | |-------------------------------------------------------------------------- 42 | | 43 | | This value controls the number of minutes until an issued token will be 44 | | considered expired. This will override any values set in the token's 45 | | "expires_at" attribute, but first-party sessions are not affected. 46 | | 47 | */ 48 | 49 | 'expiration' => null, 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | Token Prefix 54 | |-------------------------------------------------------------------------- 55 | | 56 | | Sanctum can prefix new tokens in order to take advantage of numerous 57 | | security scanning initiatives maintained by open source platforms 58 | | that notify developers if they commit tokens into repositories. 59 | | 60 | | See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning 61 | | 62 | */ 63 | 64 | 'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''), 65 | 66 | /* 67 | |-------------------------------------------------------------------------- 68 | | Sanctum Middleware 69 | |-------------------------------------------------------------------------- 70 | | 71 | | When authenticating your first-party SPA with Sanctum you may need to 72 | | customize some of the middleware Sanctum uses while processing the 73 | | request. You may change the middleware listed below as required. 74 | | 75 | */ 76 | 77 | 'middleware' => [ 78 | 'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class, 79 | 'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class, 80 | 'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class, 81 | ], 82 | 83 | ]; 84 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 6 | 'domain' => env('MAILGUN_DOMAIN'), 7 | 'secret' => env('MAILGUN_SECRET'), 8 | 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 9 | 'scheme' => 'https', 10 | ], 11 | 12 | ]; 13 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | *.sqlite-journal 3 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | $this->faker->firstName(), 17 | 'last_name' => $this->faker->lastName(), 18 | 'email' => $this->faker->unique()->safeEmail(), 19 | 'email_verified_at' => now(), 20 | 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 21 | 'remember_token' => Str::random(10), 22 | ]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 15 | $table->string('first_name'); 16 | $table->string('last_name'); 17 | $table->string('middle_name')->nullable(); 18 | $table->string('email')->unique(); 19 | $table->timestamp('email_verified_at')->nullable(); 20 | $table->string('password'); 21 | $table->rememberToken(); 22 | $table->timestamps(); 23 | }); 24 | 25 | Schema::create('password_reset_tokens', function (Blueprint $table) { 26 | $table->string('email')->primary(); 27 | $table->string('token'); 28 | $table->timestamp('created_at')->nullable(); 29 | }); 30 | 31 | Schema::create('sessions', function (Blueprint $table) { 32 | $table->string('id')->primary(); 33 | $table->foreignId('user_id')->nullable()->index(); 34 | $table->string('ip_address', 45)->nullable(); 35 | $table->text('user_agent')->nullable(); 36 | $table->longText('payload'); 37 | $table->integer('last_activity')->index(); 38 | }); 39 | } 40 | 41 | /** 42 | * Reverse the migrations. 43 | */ 44 | public function down(): void 45 | { 46 | Schema::dropIfExists('users'); 47 | Schema::dropIfExists('password_reset_tokens'); 48 | Schema::dropIfExists('sessions'); 49 | } 50 | }; 51 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000001_create_cache_table.php: -------------------------------------------------------------------------------- 1 | string('key')->primary(); 16 | $table->mediumText('value'); 17 | $table->integer('expiration'); 18 | }); 19 | 20 | Schema::create('cache_locks', function (Blueprint $table) { 21 | $table->string('key')->primary(); 22 | $table->string('owner'); 23 | $table->integer('expiration'); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | */ 30 | public function down(): void 31 | { 32 | Schema::dropIfExists('cache'); 33 | Schema::dropIfExists('cache_locks'); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000002_create_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('queue')->index(); 17 | $table->longText('payload'); 18 | $table->unsignedTinyInteger('attempts'); 19 | $table->unsignedInteger('reserved_at')->nullable(); 20 | $table->unsignedInteger('available_at'); 21 | $table->unsignedInteger('created_at'); 22 | }); 23 | 24 | Schema::create('job_batches', function (Blueprint $table) { 25 | $table->string('id')->primary(); 26 | $table->string('name'); 27 | $table->integer('total_jobs'); 28 | $table->integer('pending_jobs'); 29 | $table->integer('failed_jobs'); 30 | $table->longText('failed_job_ids'); 31 | $table->mediumText('options')->nullable(); 32 | $table->integer('cancelled_at')->nullable(); 33 | $table->integer('created_at'); 34 | $table->integer('finished_at')->nullable(); 35 | }); 36 | 37 | Schema::create('failed_jobs', function (Blueprint $table) { 38 | $table->id(); 39 | $table->string('uuid')->unique(); 40 | $table->text('connection'); 41 | $table->text('queue'); 42 | $table->longText('payload'); 43 | $table->longText('exception'); 44 | $table->timestamp('failed_at')->useCurrent(); 45 | }); 46 | } 47 | 48 | /** 49 | * Reverse the migrations. 50 | */ 51 | public function down(): void 52 | { 53 | Schema::dropIfExists('jobs'); 54 | Schema::dropIfExists('job_batches'); 55 | Schema::dropIfExists('failed_jobs'); 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_200000_add_two_factor_columns_to_users_table.php: -------------------------------------------------------------------------------- 1 | text('two_factor_secret') 17 | ->after('password') 18 | ->nullable(); 19 | 20 | $table->text('two_factor_recovery_codes') 21 | ->after('two_factor_secret') 22 | ->nullable(); 23 | 24 | if (Fortify::confirmsTwoFactorAuthentication()) { 25 | $table->timestamp('two_factor_confirmed_at') 26 | ->after('two_factor_recovery_codes') 27 | ->nullable(); 28 | } 29 | }); 30 | } 31 | 32 | /** 33 | * Reverse the migrations. 34 | */ 35 | public function down(): void 36 | { 37 | Schema::table('users', function (Blueprint $table) { 38 | $table->dropColumn(array_merge([ 39 | 'two_factor_secret', 40 | 'two_factor_recovery_codes', 41 | ], Fortify::confirmsTwoFactorAuthentication() ? [ 42 | 'two_factor_confirmed_at', 43 | ] : [])); 44 | }); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->morphs('tokenable'); 17 | $table->string('name'); 18 | $table->string('token', 64)->unique(); 19 | $table->text('abilities')->nullable(); 20 | $table->timestamp('last_used_at')->nullable(); 21 | $table->timestamp('expires_at')->nullable(); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | */ 29 | public function down(): void 30 | { 31 | Schema::dropIfExists('personal_access_tokens'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /database/migrations/2022_11_18_212346_create_bouncer_tables.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 17 | $table->string('name'); 18 | $table->string('title')->nullable(); 19 | $table->bigInteger('entity_id')->unsigned()->nullable(); 20 | $table->string('entity_type')->nullable(); 21 | $table->boolean('only_owned')->default(false); 22 | $table->json('options')->nullable(); 23 | $table->integer('scope')->nullable()->index(); 24 | $table->timestamps(); 25 | }); 26 | 27 | Schema::create(Models::table('roles'), function (Blueprint $table) { 28 | $table->bigIncrements('id'); 29 | $table->string('name'); 30 | $table->string('title')->nullable(); 31 | $table->integer('scope')->nullable()->index(); 32 | $table->timestamps(); 33 | 34 | $table->unique( 35 | ['name', 'scope'], 36 | 'roles_name_unique' 37 | ); 38 | }); 39 | 40 | Schema::create(Models::table('assigned_roles'), function (Blueprint $table) { 41 | $table->bigIncrements('id'); 42 | $table->bigInteger('role_id')->unsigned()->index(); 43 | $table->bigInteger('entity_id')->unsigned(); 44 | $table->string('entity_type'); 45 | $table->bigInteger('restricted_to_id')->unsigned()->nullable(); 46 | $table->string('restricted_to_type')->nullable(); 47 | $table->integer('scope')->nullable()->index(); 48 | 49 | $table->index( 50 | ['entity_id', 'entity_type', 'scope'], 51 | 'assigned_roles_entity_index' 52 | ); 53 | 54 | $table->foreign('role_id') 55 | ->references('id')->on(Models::table('roles')) 56 | ->onUpdate('cascade')->onDelete('cascade'); 57 | }); 58 | 59 | Schema::create(Models::table('permissions'), function (Blueprint $table) { 60 | $table->bigIncrements('id'); 61 | $table->bigInteger('ability_id')->unsigned()->index(); 62 | $table->bigInteger('entity_id')->unsigned()->nullable(); 63 | $table->string('entity_type')->nullable(); 64 | $table->boolean('forbidden')->default(false); 65 | $table->integer('scope')->nullable()->index(); 66 | 67 | $table->index( 68 | ['entity_id', 'entity_type', 'scope'], 69 | 'permissions_entity_index' 70 | ); 71 | 72 | $table->foreign('ability_id') 73 | ->references('id')->on(Models::table('abilities')) 74 | ->onUpdate('cascade')->onDelete('cascade'); 75 | }); 76 | } 77 | 78 | /** 79 | * Reverse the migrations. 80 | */ 81 | public function down(): void 82 | { 83 | Schema::drop(Models::table('permissions')); 84 | Schema::drop(Models::table('assigned_roles')); 85 | Schema::drop(Models::table('roles')); 86 | Schema::drop(Models::table('abilities')); 87 | } 88 | }; 89 | -------------------------------------------------------------------------------- /database/migrations/2023_10_07_114319_create_media_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | 17 | $table->morphs('model'); 18 | $table->uuid('uuid')->nullable()->unique(); 19 | $table->string('collection_name'); 20 | $table->string('name'); 21 | $table->string('file_name'); 22 | $table->string('mime_type')->nullable(); 23 | $table->string('disk'); 24 | $table->string('conversions_disk')->nullable(); 25 | $table->unsignedBigInteger('size'); 26 | $table->json('manipulations'); 27 | $table->json('custom_properties'); 28 | $table->json('generated_conversions'); 29 | $table->json('responsive_images'); 30 | $table->unsignedInteger('order_column')->nullable()->index(); 31 | 32 | $table->nullableTimestamps(); 33 | }); 34 | } 35 | 36 | /** 37 | * Reverse the migrations. 38 | */ 39 | public function down() 40 | { 41 | Schema::dropIfExists('media'); 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /database/seeders/BouncerSeeder.php: -------------------------------------------------------------------------------- 1 | everything(); 17 | Bouncer::allow('regular')->to('edit-profile', User::class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /database/seeders/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call([ 15 | BouncerSeeder::class, 16 | UsersTableSeeder::class, 17 | ]); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /database/seeders/UsersTableSeeder.php: -------------------------------------------------------------------------------- 1 | create( 17 | [ 18 | 'first_name' => 'Luke', 19 | 'last_name' => 'Skywalker', 20 | 'email' => 'luke@jedi.com', 21 | 'email_verified_at' => null, 22 | 'password' => bcrypt('123123'), 23 | ] 24 | ); 25 | 26 | Bouncer::assign('admin')->to($users->first()); 27 | 28 | $others = User::factory(20)->create(); 29 | foreach ($others as $model) { 30 | Bouncer::assign('regular')->to($model); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "@/*": ["./resources/app/*"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'password' => 'The provided password is incorrect.', 18 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 19 | 20 | ]; 21 | -------------------------------------------------------------------------------- /lang/en/frontend.php: -------------------------------------------------------------------------------- 1 | [ 15 | 'status' => [ 16 | 'verified' => 'Verified', 17 | 'not_verified' => 'Not verified', 18 | 'ask_verify' => 'Verify Email', 19 | ], 20 | 'roles' => [ 21 | 'regular' => 'Regular', 22 | 'admin' => 'Admin', 23 | ], 24 | 'labels' => [ 25 | 'id' => 'ID', 26 | 'id_pound' => '#', 27 | 'first_name' => 'First name', 28 | 'last_name' => 'Last name', 29 | 'middle_name' => 'Middle name', 30 | 'name' => 'Name', 31 | 'avatar' => 'Avatar', 32 | 'email' => 'Email', 33 | 'role' => 'Role', 34 | 'roles' => 'Roles', 35 | 'status' => 'Status', 36 | 'current_password' => 'Current Password', 37 | 'password' => 'Password', 38 | 'new_password' => 'New Password', 39 | 'confirm_password' => 'Confirm Password', 40 | 'ask_upload_avatar' => 'Upload Avatar', 41 | 'new_record' => 'New User', 42 | 'edit_record' => 'Edit User', 43 | 'general_settings' => 'General Settings', 44 | 'password_settings' => 'Password Settings', 45 | 'avatar_settings' => 'Avatar Settings', 46 | ], 47 | ], 48 | 'messages' => [ 49 | 'name' => 'Message', 50 | ], 51 | 'global' => [ 52 | 'pages' => [ 53 | 'home' => 'Dashboard', 54 | 'users' => 'Users', 55 | 'users_create' => 'New User', 56 | 'users_edit' => 'Edit User', 57 | 'profile' => 'Profile', 58 | 'register' => 'Register', 59 | 'login' => 'Login', 60 | 'logout' => 'Logout', 61 | 'forgot_password' => 'Forgot Password', 62 | 'reset_password' => 'Reset Password', 63 | ], 64 | 'phrases' => [ 65 | 'clear_filters' => 'Clear all', 66 | 'loading' => 'Loading...', 67 | 'sign_out' => 'Sign Out', 68 | 'all_records' => 'All Records', 69 | 'argh' => 'Argh!', 70 | 'success' => 'Success!', 71 | 'fix_errors' => 'Please fix the following errors:', 72 | 'no_records' => 'No records found.', 73 | 'login_desc' => 'If you are already a member, easily log in.', 74 | 'login_not_verified' => 'Please verify your email in order to be able to log in.', 75 | 'register_desc' => 'If you don\'t have an account, register.', 76 | 'reset_password_desc' => 'Fill the form to reset your password.', 77 | 'login_ask' => 'Already have an account?', 78 | 'register_ask' => 'Don\'t have an account?', 79 | 'forgot_password_desc' => 'If you forgot your password, reset it below.', 80 | 'forgot_password_ask' => 'Forgot your password?', 81 | 'forgot_password_login' => 'Got your password? Log in.', 82 | 'already_registered_login' => 'Already done? Login.', 83 | 'inspire' => "Let's build something fun!", 84 | 'copyright' => sprintf('Copyright © %s. %s. All Rights Reserved.', date('Y'), env('APP_NAME')), 85 | 'record_created' => 'Record created successfully.', 86 | 'record_not_created' => 'Unable to create record.', 87 | 'record_updated' => 'Record updated successfully.', 88 | 'record_not_updated' => 'Unable to update record.', 89 | 'file_uploaded' => 'File uploaded successfully', 90 | 'file_not_uploaded' => 'Unable to upload file', 91 | 'password_updated' => 'Password updated successfully', 92 | 'password_not_updated' => 'Unable to update password', 93 | 'profile_updated' => 'Profile updated successfully', 94 | 'profile_not_updated' => 'Unable to update password', 95 | 'not_found_title' => '404', 96 | 'not_found_text' => 'The page you\'re looking for is not here.', 97 | 'not_found_back' => 'Go back', 98 | 'input_files_select' => 'Drop files here or click to upload | Drop file here or click to upload', 99 | 'input_files_selected' => '{count} file selected | {count} files selected', 100 | 'email_verified' => 'Email verified successfully!', 101 | 'member_since' => 'Member since: {date}', 102 | 'verification_sent' => 'Email verification link sent.', 103 | ], 104 | 'buttons' => [ 105 | 'add_new' => 'Add New', 106 | 'filters' => 'Filters', 107 | 'save' => 'Save', 108 | 'send' => 'Send', 109 | 'submit' => 'Submit', 110 | 'login' => 'Login', 111 | 'register' => 'Register', 112 | 'search' => 'Search', 113 | 'new_record' => 'New Record', 114 | 'documentation' => 'Documentation', 115 | 'back' => 'Back', 116 | 'upload' => 'Upload', 117 | 'update' => 'Update', 118 | 'change_avatar' => 'Change Avatar', 119 | ], 120 | 'actions' => [ 121 | 'name' => 'Actions', 122 | 'edit' => 'Edit', 123 | 'delete' => 'Delete', 124 | ], 125 | 'alerts' => [ 126 | 'success' => 'Success!', 127 | 'warning' => 'Warning!', 128 | 'danger' => 'Error!', 129 | 'confirm' => 'Confirm!', 130 | 'confirm_action_message' => 'Are you sure you want to perform this action?', 131 | ], 132 | ], 133 | ]; 134 | -------------------------------------------------------------------------------- /lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Your password has been reset!', 17 | 'sent' => 'We have emailed your password reset link!', 18 | 'throttled' => 'Please wait before retrying.', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that email address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "private": true, 4 | "env": { 5 | "node": true, 6 | "vue/setup-compiler-macros": true 7 | }, 8 | "scripts": { 9 | "dev": "vite", 10 | "build": "vite build --mode production", 11 | "prod": "vite build --mode production", 12 | "watch": "vite build --mode development --watch --minify=false" 13 | }, 14 | "dependencies": { 15 | "@vitejs/plugin-vue": "^4.6.2", 16 | "fork-awesome": "^1.2.0", 17 | "js-cookie": "^3.0.5", 18 | "pinia": "^2.1.7", 19 | "resolve-url-loader": "^5.0.0", 20 | "vite-plugin-resolve-extension-vue": "^0.1.0", 21 | "vue": "^3.4.27", 22 | "vue-i18n": "^9.13.1", 23 | "vue-loader": "^17.4.2", 24 | "vue-multiselect": "^3.0.0", 25 | "vue-router": "^4.3.2" 26 | }, 27 | "devDependencies": { 28 | "@tailwindcss/aspect-ratio": "^0.4.2", 29 | "@tailwindcss/forms": "^0.5.7", 30 | "@tailwindcss/line-clamp": "^0.4.4", 31 | "@tailwindcss/typography": "^0.5.13", 32 | "cross-env": "^7.0.3", 33 | "lodash": "^4.17.21", 34 | "sass": "^1.77.4", 35 | "sass-loader": "^14.2.1", 36 | "typescript": "^5.4.5", 37 | "autoprefixer": "^10.4.2", 38 | "axios": "^1.6.4", 39 | "laravel-vite-plugin": "^1.0.0", 40 | "postcss": "^8.4.31", 41 | "tailwindcss": "^3.1.0", 42 | "vite": "^5.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | ./tests/Unit 10 | 11 | 12 | ./tests/Feature 13 | 14 | 15 | 16 | 17 | ./app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Redirect Trailing Slashes If Not A Folder... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_URI} (.+)/$ 15 | RewriteRule ^ %1 [L,R=301] 16 | 17 | # Send Requests To Front Controller... 18 | RewriteCond %{REQUEST_FILENAME} !-d 19 | RewriteCond %{REQUEST_FILENAME} !-f 20 | RewriteRule ^ index.php [L] 21 | 22 | -------------------------------------------------------------------------------- /public/assets/images/login.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdarko/laravel-vue-starter/1d5f82f018497af95b349ace62823e5818c1712a/public/assets/images/login.jpg -------------------------------------------------------------------------------- /public/assets/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdarko/laravel-vue-starter/1d5f82f018497af95b349ace62823e5818c1712a/public/assets/images/logo.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdarko/laravel-vue-starter/1d5f82f018497af95b349ace62823e5818c1712a/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | handleRequest(Request::capture()); 18 | -------------------------------------------------------------------------------- /public/mix-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "/js/main.js": "/js/main.js", 3 | "/js/not-found.js": "/js/not-found.js", 4 | "/css/main.css": "/css/main.css" 5 | } 6 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /public/web.config: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /resources/app/helpers/alert.js: -------------------------------------------------------------------------------- 1 | import {trans} from "@/helpers/i18n"; 2 | 3 | /** 4 | * Custom alert message 5 | * @param type 6 | * @param message 7 | * @param title 8 | * @private 9 | */ 10 | const _message = function (type, message, title = '') { 11 | if (!title) { 12 | for (var i in ['success', 'warning', 'danger']) { 13 | if (type === i) { 14 | title = trans('global.alerts.' + i); 15 | break; 16 | } 17 | } 18 | } 19 | window.alert(title + ' ' + message); 20 | 21 | } 22 | 23 | /** 24 | * Custom confirm alert 25 | * @param func_if_yes 26 | * @param func_if_cancel 27 | * @param msg 28 | * @param title 29 | * @param type 30 | * @private 31 | */ 32 | const _confirm = function (func_if_yes, func_if_cancel, msg, title, type) { 33 | 34 | // Default implementation 35 | if (!type) { 36 | type = 'success'; 37 | } 38 | if (!msg) { 39 | msg = trans('global.alerts.confirm_action_message'); 40 | } 41 | if (!title) { 42 | title = trans('global.alerts.confirm'); 43 | } 44 | msg = title + ' - ' + msg; 45 | if (window.confirm(msg)) { 46 | if (func_if_yes) { 47 | func_if_yes(); 48 | } 49 | } else { 50 | if (func_if_cancel) { 51 | func_if_cancel(); 52 | } 53 | } 54 | // Swal implementation 55 | /* 56 | swal($.extend({ 57 | title: title, 58 | text: msg, 59 | type: type, 60 | showCancelButton: true, 61 | cancelButtonText: "Cancelar", 62 | confirmButtonText: "Ok", 63 | allowEscapeKey: false, 64 | allowOutsideClick: false 65 | }, params || {}) 66 | ).then(function(isConfirm) { 67 | if (isConfirm && func_if_yes instanceof Function){ 68 | func_if_yes(); 69 | } 70 | }, function(dismiss) { 71 | // dismiss can be 'cancel', 'overlay', 'close', 'timer' 72 | if (dismiss === 'cancel' && func_if_cancel instanceof Function) { 73 | func_if_cancel() 74 | } 75 | })*/ 76 | }; 77 | 78 | /** 79 | * Success alert 80 | * @param message 81 | * @param title 82 | */ 83 | const messageSuccess = function (message, title = '') { 84 | _message('success', message, title); 85 | } 86 | 87 | /** 88 | * Warning alert 89 | * @param message 90 | * @param title 91 | */ 92 | const messageWarning = function (message, title = '') { 93 | _message('warning', message, title); 94 | } 95 | 96 | /** 97 | * Danger alert 98 | * @param message 99 | * @param title 100 | */ 101 | const messageDanger = function (message, title = '') { 102 | _message('danger', message, title); 103 | } 104 | 105 | /** 106 | * Success confirmation 107 | * @param callback_yes 108 | * @param callback_cancel 109 | * @param msg 110 | * @param title 111 | */ 112 | const confirmSuccess = function (callback_yes, callback_cancel, msg, title) { 113 | _confirm(callback_yes, callback_cancel, msg, title, 'success') 114 | } 115 | 116 | /** 117 | * Warning confirmation 118 | * @param callback_yes 119 | * @param callback_cancel 120 | * @param msg 121 | * @param title 122 | */ 123 | const confirmWarning = function (callback_yes, callback_cancel, msg, title) { 124 | _confirm(callback_yes, callback_cancel, msg, title, 'warning') 125 | } 126 | 127 | /** 128 | * Danger confirmation 129 | * @param callback_yes 130 | * @param callback_cancel 131 | * @param msg 132 | * @param title 133 | */ 134 | const confirmDanger = function (callback_yes, callback_cancel, msg, title) { 135 | _confirm(callback_yes, callback_cancel, msg, title, 'danger') 136 | } 137 | 138 | 139 | export default { 140 | messageSuccess, 141 | messageWarning, 142 | messageDanger, 143 | confirmSuccess, 144 | confirmWarning, 145 | confirmDanger 146 | } 147 | -------------------------------------------------------------------------------- /resources/app/helpers/api.js: -------------------------------------------------------------------------------- 1 | export function getFirstErrorFromResponse(error) { 2 | let errorFormatted = getResponseError(error) 3 | let errorMessage = ''; 4 | if (typeof errorFormatted === 'object') { 5 | for (let i in errorFormatted) { 6 | errorMessage = Array.isArray(errorFormatted[i]) ? errorFormatted[i][0] : 'Error'; 7 | break; 8 | } 9 | } else if(typeof errorFormatted === 'string') { 10 | errorMessage = errorFormatted; 11 | } 12 | return errorMessage; 13 | } 14 | 15 | export function getResponseError(error, response) { 16 | const errorMessage = "API Error, please try again."; 17 | if (typeof error !== 'object') { 18 | return errorMessage; 19 | } 20 | 21 | if (error.name === "Fetch User") { 22 | return error.message; 23 | } 24 | 25 | if (error.hasOwnProperty('response') && error.response.hasOwnProperty('data') && error.response.data.hasOwnProperty('errors')) { 26 | return error.response.data.errors; 27 | } 28 | 29 | if (error.hasOwnProperty('response') && error.response.hasOwnProperty('data') && error.response.data.hasOwnProperty('message')) { 30 | return error.response.data.message; 31 | } 32 | 33 | if (error.hasOwnProperty('message')) { 34 | return error.message; 35 | } 36 | 37 | if (!error.response) { 38 | console.error(`API ${error.config.url} not found`); 39 | return errorMessage; 40 | } 41 | if (process.env.NODE_ENV === "development") { 42 | console.error(error.response.data); 43 | console.error(error.response.status); 44 | console.error(error.response.headers); 45 | } 46 | 47 | return errorMessage; 48 | } 49 | 50 | export function prepareQuery(args) { 51 | let page = args.hasOwnProperty('page') ? args.page : null 52 | let search = args.hasOwnProperty('search') ? args.search : null; 53 | let sort = args.hasOwnProperty('sort') ? args.sort : null; 54 | let filters = args.hasOwnProperty('filters') ? args.filters : null; 55 | let params = {page: page} 56 | if (search) { 57 | params.search = search; 58 | } 59 | if (sort && sort.hasOwnProperty('column') && sort.hasOwnProperty('direction')) { 60 | if (sort.column && sort.direction) { 61 | params.sort_by = sort.column; 62 | params.sort = sort.direction; 63 | } 64 | } 65 | if (filters) { 66 | for (let key in filters) { 67 | if (!filters[key] || (filters[key].hasOwnProperty('value') && !filters[key].value)) { 68 | continue; 69 | } 70 | let comparison = filters[key].hasOwnProperty('comparison') ? filters[key].comparison : '='; 71 | let values = Array.isArray(filters[key].value) ? filters[key].value : [filters[key].value]; 72 | let cleanValues = []; 73 | for(let i in values) { 74 | if('object' === (typeof values[i])) { 75 | if(values[i].hasOwnProperty('id')) { 76 | cleanValues.push(values[i].id); 77 | } 78 | } else { 79 | cleanValues.push(values[i]); 80 | } 81 | } 82 | if(cleanValues.length > 0) { 83 | params['filters[' + key + ']'] = key + ';' + comparison + ';' + cleanValues.join('|'); 84 | } 85 | } 86 | } 87 | 88 | return params; 89 | } 90 | -------------------------------------------------------------------------------- /resources/app/helpers/data.js: -------------------------------------------------------------------------------- 1 | export function fillObject(object, data) { 2 | for (let i in object) { 3 | if (data.hasOwnProperty(i)) { 4 | object[i] = data[i]; 5 | } 6 | } 7 | return object; 8 | } 9 | 10 | /** 11 | * Flatten a multidimensional object 12 | * 13 | * For example: 14 | * flattenObject{ a: 1, b: { c: 2 } } 15 | * Returns: 16 | * { a: 1, c: 2} 17 | */ 18 | export const flattenObjectAsArray = (arr, prop) => { 19 | var a = []; 20 | for (let i = 0; i < arr.length; i++) { 21 | let o = arr[i]; 22 | if (o[prop]) { 23 | let c = flattenObjectAsArray(o[prop], prop); 24 | if (c) { 25 | a = a.concat(c); 26 | } 27 | } 28 | a.push(o) 29 | } 30 | return a; 31 | } 32 | 33 | /** 34 | * Clears object values 35 | * @param object 36 | */ 37 | export const clearObject = (object) => { 38 | for (let i in object) { 39 | object[i] = null; 40 | } 41 | }; 42 | 43 | /** 44 | * Reduce properties 45 | * @param data 46 | * @param properties 47 | * @param singleProperty 48 | * @returns {*} 49 | */ 50 | export const reduceProperties = (data, properties, singleProperty) => { 51 | let obj = {}; 52 | for (let i in data) { 53 | obj[i] = data[i]; 54 | } 55 | if (!Array.isArray(properties)) { 56 | properties = [properties]; 57 | } 58 | for (let i in properties) { 59 | if (obj.hasOwnProperty(properties[i])) { 60 | let value = obj[properties[i]]; 61 | let newVal; 62 | if (Array.isArray(value)) { 63 | newVal = []; 64 | for (let j in value) { 65 | newVal[j] = value[j] && value[j].hasOwnProperty(singleProperty) ? value[j][singleProperty] : newVal; 66 | } 67 | } else if (typeof value === 'object') { 68 | newVal = value && value.hasOwnProperty(singleProperty) ? value[singleProperty] : newVal; 69 | } else { 70 | newVal = value; 71 | } 72 | obj[properties[i]] = newVal; 73 | } 74 | } 75 | 76 | return obj; 77 | }; 78 | -------------------------------------------------------------------------------- /resources/app/helpers/i18n.js: -------------------------------------------------------------------------------- 1 | import i18n from "@/plugins/i18n" 2 | 3 | export function trans(key, params = {}) { 4 | const {t} = i18n.global; 5 | return t(key, params) 6 | } 7 | -------------------------------------------------------------------------------- /resources/app/helpers/routing.js: -------------------------------------------------------------------------------- 1 | import {flattenObjectAsArray} from "@/helpers/data"; 2 | import routes from "@/router/routes"; 3 | 4 | export const getAbilitiesForRoute = function (names) { 5 | 6 | if (!Array.isArray(names)) { 7 | names = [names]; 8 | } 9 | 10 | let objects = flattenObjectAsArray(routes, 'children'); 11 | let abilities = []; 12 | for (let j in names) { 13 | 14 | 15 | for (let i in objects) { 16 | if (objects[i].hasOwnProperty('name') && objects[i].name === names[j] && objects[i].hasOwnProperty('meta') && objects[i].meta.hasOwnProperty('requiresAbility')) { 17 | abilities.push(objects[i].meta.requiresAbility); 18 | } 19 | } 20 | } 21 | 22 | return abilities; 23 | } 24 | 25 | 26 | export const toUrl = function (page) { 27 | if (page.charAt(0) === '/') { 28 | page = page.substring(1); 29 | } 30 | return `/panel/${page}`; 31 | } 32 | -------------------------------------------------------------------------------- /resources/app/main.js: -------------------------------------------------------------------------------- 1 | import {createApp} from 'vue' 2 | import { createPinia } from 'pinia' 3 | 4 | import router from "@/router"; 5 | import i18n from "@/plugins/i18n"; 6 | import App from "@/App"; 7 | 8 | const app = createApp(App) 9 | 10 | app.use(createPinia()); 11 | 12 | app.use(router); 13 | app.use(i18n); 14 | 15 | app.mount('#app'); 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /resources/app/plugins/axios.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | axios.defaults.withCredentials = true; 4 | axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 5 | axios.defaults.headers.common['X-Locale'] = localStorage.hasOwnProperty('locale') ? localStorage.locale : window.AppConfig.defaultLocale; 6 | axios.defaults.headers.common['Content-Type'] = 'application/json'; 7 | axios.defaults.baseURL = window.AppConfig.url; 8 | 9 | export default axios; 10 | -------------------------------------------------------------------------------- /resources/app/plugins/i18n.js: -------------------------------------------------------------------------------- 1 | import {createI18n} from 'vue-i18n' 2 | 3 | const messages = window.AppConfig.locales; 4 | 5 | let defaultLocale = window.AppConfig.defaultLocale; 6 | 7 | const i18n = createI18n({ 8 | locale: localStorage.locale ?? defaultLocale, 9 | fallbackLocale: defaultLocale, 10 | messages, 11 | legacy: false, 12 | }) 13 | 14 | export default i18n; 15 | -------------------------------------------------------------------------------- /resources/app/router/index.js: -------------------------------------------------------------------------------- 1 | import {createWebHistory, createRouter} from "vue-router"; 2 | 3 | import routes from "@/router/routes"; 4 | 5 | import {useAuthStore} from "@/stores/auth"; 6 | 7 | const router = createRouter({ 8 | history: createWebHistory(), 9 | linkActiveClass: 'active', 10 | routes, 11 | }) 12 | 13 | router.beforeEach(async (to, from, next) => { 14 | const authStore = useAuthStore(); 15 | const requiresAbility = to?.meta?.requiresAbility; 16 | const requiresAuth = to?.meta?.requiresAuth; 17 | const belongsToOwnerOnly = to?.meta?.isOwner; 18 | 19 | if (!authStore.user) { 20 | await authStore.getCurrentUser(); 21 | } 22 | if (!authStore.user) { 23 | authStore.clearBrowserData(); 24 | if(requiresAuth) { 25 | next({name: 'login'}) 26 | } 27 | } 28 | 29 | if(to?.meta?.isPublicAuthPage && authStore.user) { 30 | next({name: 'dashboard'}) 31 | return; 32 | } 33 | 34 | if (requiresAbility && requiresAuth) { 35 | if (authStore.hasAbilities(requiresAbility)) { 36 | next() 37 | } else { 38 | next({ 39 | name: 'profile' 40 | }) 41 | } 42 | } else if (belongsToOwnerOnly) { 43 | if (authStore.user.is_owner) { 44 | next() 45 | } else { 46 | next({name: 'dashboard'}) 47 | } 48 | } else { 49 | next() 50 | } 51 | }) 52 | 53 | export default router; 54 | -------------------------------------------------------------------------------- /resources/app/router/routes.js: -------------------------------------------------------------------------------- 1 | import {default as PageLogin} from "@/views/pages/auth/login/Main"; 2 | import {default as PageRegister} from "@/views/pages/auth/register/Main"; 3 | import {default as PageResetPassword} from "@/views/pages/auth/reset-password/Main"; 4 | import {default as PageForgotPassword} from "@/views/pages/auth/forgot-password/Main"; 5 | import {default as PageNotFound} from "@/views/pages/shared/404/Main"; 6 | 7 | import {default as PageDashboard} from "@/views/pages/private/dashboard/Main"; 8 | import {default as PageProfile} from "@/views/pages/private/profile/Main"; 9 | 10 | import {default as PageUsers} from "@/views/pages/private/users/Index"; 11 | import {default as PageUsersCreate} from "@/views/pages/private/users/Create"; 12 | import {default as PageUsersEdit} from "@/views/pages/private/users/Edit"; 13 | 14 | import abilities from "@/stub/abilities"; 15 | 16 | const routes = [ 17 | { 18 | name: "home", 19 | path: "/", 20 | meta: {requiresAuth: false, isPublicAuthPage: true}, 21 | component: PageLogin, 22 | }, 23 | { 24 | name: "panel", 25 | path: "/panel", 26 | children: [ 27 | { 28 | name: "dashboard", 29 | path: "dashboard", 30 | meta: {requiresAuth: true}, 31 | component: PageDashboard, 32 | }, 33 | { 34 | name: "profile", 35 | path: "profile", 36 | meta: {requiresAuth: true, isOwner: true}, 37 | component: PageProfile, 38 | }, 39 | { 40 | path: "users", 41 | children: [ 42 | { 43 | name: "users.list", 44 | path: "list", 45 | meta: {requiresAuth: true, requiresAbility: abilities.LIST_USER}, 46 | component: PageUsers, 47 | }, 48 | { 49 | name: "users.create", 50 | path: "create", 51 | meta: {requiresAuth: true, requiresAbility: abilities.CREATE_USER}, 52 | component: PageUsersCreate, 53 | }, 54 | { 55 | name: "users.edit", 56 | path: ":id/edit", 57 | meta: {requiresAuth: true, requiresAbility: abilities.EDIT_USER}, 58 | component: PageUsersEdit, 59 | }, 60 | ] 61 | }, 62 | ] 63 | }, 64 | { 65 | path: "/login", 66 | name: "login", 67 | meta: {requiresAuth: false, isPublicAuthPage: true}, 68 | component: PageLogin, 69 | }, 70 | { 71 | path: "/register", 72 | name: "register", 73 | meta: {requiresAuth: false, isPublicAuthPage: true}, 74 | component: PageRegister, 75 | }, 76 | { 77 | path: "/reset-password", 78 | name: "resetPassword", 79 | meta: {requiresAuth: false, isPublicAuthPage: true}, 80 | component: PageResetPassword, 81 | }, 82 | { 83 | path: "/forgot-password", 84 | name: "forgotPassword", 85 | meta: {requiresAuth: false, isPublicAuthPage: true}, 86 | component: PageForgotPassword, 87 | }, 88 | { 89 | path: "/:catchAll(.*)", 90 | name: "notFound", 91 | meta: {requiresAuth: false}, 92 | component: PageNotFound, 93 | }, 94 | ] 95 | 96 | export default routes; 97 | -------------------------------------------------------------------------------- /resources/app/services/AuthService.ts: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import BaseService from "@/services/BaseService"; 3 | import {useGlobalStateStore} from "@/stores/global" 4 | 5 | export default class AuthService extends BaseService { 6 | 7 | private globalStateStore; 8 | 9 | constructor() { 10 | super(); 11 | this.url = '/'; 12 | this.setupAPI(axios.defaults.baseURL); 13 | this.globalStateStore = useGlobalStateStore(); 14 | } 15 | 16 | async getCurrentUser() { 17 | await this.get("/sanctum/csrf-cookie"); 18 | return this.get("/api/users/auth"); 19 | } 20 | 21 | async forgotPassword(payload) { 22 | this.globalStateStore.loadingElements['forgot-password-form'] = true; 23 | await this.get("/sanctum/csrf-cookie"); 24 | return this.post("/forgot-password", payload).finally(() => { 25 | this.globalStateStore.loadingElements['forgot-password-form'] = false; 26 | }); 27 | } 28 | 29 | async resetPassword(payload) { 30 | this.globalStateStore.loadingElements['reset-password-form'] = true; 31 | await this.get("/sanctum/csrf-cookie"); 32 | return this.post("/reset-password", payload).finally(() => { 33 | this.globalStateStore.loadingElements['reset-password-form'] = false; 34 | }); 35 | } 36 | 37 | async registerUser(payload) { 38 | this.globalStateStore.loadingElements['register-form'] = true; 39 | await this.get("/sanctum/csrf-cookie"); 40 | return this.post("/register", payload).finally(() => { 41 | this.globalStateStore.loadingElements['register-form'] = false; 42 | }); 43 | } 44 | 45 | async updatePassword(payload) { 46 | this.globalStateStore.loadingElements['update-password-form'] = true; 47 | await this.get("/sanctum/csrf-cookie"); 48 | return this.put("/user/password", payload).finally(() => { 49 | this.globalStateStore.loadingElements['update-password-form'] = false; 50 | }); 51 | } 52 | 53 | async sendVerification(payload) { 54 | this.globalStateStore.loadingElements['send-verification-form'] = true; 55 | await this.get("/sanctum/csrf-cookie"); 56 | return this.post("/email/verification-notification", payload).finally(() => { 57 | this.globalStateStore.loadingElements['send-verification-form'] = false; 58 | }); 59 | } 60 | 61 | async updateUser(payload) { 62 | this.globalStateStore.loadingElements['update-profile-form'] = true; 63 | await this.get("/sanctum/csrf-cookie"); 64 | return this.put("/user/profile-information", payload).finally(() => { 65 | this.globalStateStore.loadingElements['update-profile-form'] = false; 66 | }); 67 | } 68 | 69 | login(payload) { 70 | this.globalStateStore.loadingElements['login-form'] = true; 71 | return this.post("/login", payload).finally(() => { 72 | this.globalStateStore.loadingElements['login-form'] = false; 73 | }); 74 | } 75 | 76 | logout() { 77 | this.globalStateStore.loadingElements['logout-form'] = true; 78 | return this.post("/logout", {}, {}).finally(() => { 79 | this.globalStateStore.loadingElements['logout-form'] = false; 80 | }); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /resources/app/services/BaseService.ts: -------------------------------------------------------------------------------- 1 | import axios from "@/plugins/axios" 2 | import type {AxiosInstance} from "axios"; 3 | 4 | export default abstract class BaseService { 5 | 6 | api: AxiosInstance; 7 | url: string; 8 | 9 | setupAPI(baseURL) { 10 | this.api = axios.create({ 11 | baseURL: baseURL, 12 | withCredentials: true, 13 | }); 14 | this.api.interceptors.response.use( 15 | (response) => { 16 | return response; 17 | }, 18 | function (error) { 19 | let data = window.localStorage.getItem('currentUser'); 20 | if ( 21 | error.response && 22 | [401, 419].includes(error.response.status) && 23 | data 24 | ) { 25 | let tmpAxios = axios.create({ 26 | withCredentials: true, 27 | }); 28 | tmpAxios.post("/logout").then((r) => { 29 | window.location.href = '/'; 30 | }) 31 | } 32 | return Promise.reject(error); 33 | }, 34 | ) 35 | } 36 | 37 | 38 | protected post(url, data, config = {}) { 39 | if(!config) { 40 | config = {}; 41 | } 42 | if(data instanceof FormData) { 43 | config = this.setHeaders(config); 44 | } 45 | return this.api.post(url, data, config); 46 | } 47 | 48 | protected put(url, data, config = {}) { 49 | if(!config) { 50 | config = {}; 51 | } 52 | if(data instanceof FormData) { 53 | config = this.setHeaders(config); 54 | data.append('_method', 'PUT'); 55 | } else { 56 | data._method = 'PUT'; 57 | } 58 | return this.api.post(url, data, config); 59 | } 60 | 61 | protected patch(url, data, config = {}) { 62 | if(!config) { 63 | config = {}; 64 | } 65 | if(data instanceof FormData) { 66 | config = this.setHeaders(config); 67 | data.append('_method', 'PATCH'); 68 | } else { 69 | data._method = 'PATCH'; 70 | } 71 | return this.api.post(url, data, config); 72 | } 73 | 74 | protected get(url, config = {}) { 75 | return this.api.get(url, config); 76 | } 77 | 78 | protected delete(url, config = {}) { 79 | return this.api.delete(url, config); 80 | } 81 | 82 | protected setHeaders(config) { 83 | if(!config) { 84 | config = {}; 85 | } 86 | if(!config?.headers) { 87 | config.headers = {}; 88 | } 89 | config.headers['Content-Type'] = 'multipart/form-data'; 90 | return config; 91 | } 92 | } 93 | 94 | -------------------------------------------------------------------------------- /resources/app/services/ModelService.ts: -------------------------------------------------------------------------------- 1 | import BaseService from "@/services/BaseService"; 2 | import axios from "@/plugins/axios"; 3 | 4 | import {useAlertStore} from "@/stores"; 5 | import {getResponseError} from "@/helpers/api"; 6 | 7 | import {useGlobalStateStore} from "@/stores"; 8 | 9 | export default abstract class ModelService extends BaseService { 10 | 11 | constructor() { 12 | super(); 13 | this.setupAPI(axios.defaults.baseURL + '/api'); 14 | } 15 | 16 | public create() { 17 | return this.get(this.url + `/create`, {}); 18 | } 19 | 20 | public find(object_id) { 21 | return this.get(this.url + `/${object_id}`, {}); 22 | } 23 | 24 | public edit(object_id) { 25 | return this.get(this.url + `/${object_id}/edit`, {}); 26 | } 27 | 28 | public store(payload) { 29 | let data = this.transformPayloadForSubmission(payload); 30 | return this.post(this.url, data, { 31 | headers: { 32 | 'Content-Type': 'multipart/form-data' 33 | }, 34 | }) 35 | } 36 | 37 | public update(object_id, payload) { 38 | let data = this.transformPayloadForSubmission(payload); 39 | return this.patch(this.url + `/${object_id}`, data, { 40 | headers: { 41 | 'Content-Type': 'multipart/form-data' 42 | }, 43 | }); 44 | } 45 | 46 | public delete(object_id) { 47 | return super.delete(this.url + `/${object_id}`, {}); 48 | } 49 | 50 | public index(params = {}) { 51 | let path = this.url; 52 | let query = new URLSearchParams(params).toString(); 53 | if (query) { 54 | path += '?' + query 55 | } 56 | return this.get(path, {}); 57 | } 58 | 59 | public handleUpdate(ui_element_id, object_id, data) { 60 | const alertStore = useAlertStore(); 61 | const globalUserState = useGlobalStateStore(); 62 | globalUserState.loadingElements[ui_element_id] = true; 63 | return this.update(object_id, data).then((response) => { 64 | let answer = response.data; 65 | alertStore.success(answer.message); 66 | }).catch((error) => { 67 | alertStore.error(getResponseError(error)); 68 | }).finally(() => { 69 | globalUserState.loadingElements[ui_element_id] = false; 70 | }) 71 | } 72 | 73 | public handleCreate(ui_element_id, data) { 74 | const alertStore = useAlertStore(); 75 | const globalUserState = useGlobalStateStore(); 76 | globalUserState.setElementLoading(ui_element_id, true); 77 | return this.store(data).then((response) => { 78 | let answer = response.data; 79 | alertStore.success(answer.message); 80 | }).catch((error) => { 81 | alertStore.error(getResponseError(error)); 82 | }).finally(() => { 83 | globalUserState.setElementLoading(ui_element_id, false); 84 | }) 85 | } 86 | 87 | public transformPayloadForSubmission(model: any, form: FormData = null, namespace = ''): FormData { 88 | let formData = form || new FormData(); 89 | let formKey; 90 | for (let propertyName in model) { 91 | if (!model.hasOwnProperty(propertyName) || !model[propertyName]) continue; 92 | let formKey = namespace ? `${namespace}[${propertyName}]` : propertyName; 93 | if (model[propertyName] instanceof Date) { 94 | formData.append(formKey, model[propertyName].toISOString()); 95 | } else if (model[propertyName] instanceof Array) { 96 | model[propertyName].forEach((element, index) => { 97 | const tempFormKey = `${formKey}[${index}]`; 98 | if(element instanceof Array) { 99 | this.transformPayloadForSubmission(element, formData, tempFormKey); 100 | } else { 101 | formData.append(tempFormKey, element.toString()); 102 | } 103 | }); 104 | } else if (typeof model[propertyName] === 'object') { 105 | if(model[propertyName] instanceof File) { 106 | formData.append(formKey, model[propertyName]); 107 | } else { 108 | this.transformPayloadForSubmission(model[propertyName], formData, formKey); 109 | } 110 | } else { 111 | formData.append(formKey, model[propertyName].toString()); 112 | } 113 | } 114 | return formData; 115 | }; 116 | } 117 | -------------------------------------------------------------------------------- /resources/app/services/SearchService.ts: -------------------------------------------------------------------------------- 1 | import BaseService from "@/services/BaseService"; 2 | import axios from "axios"; 3 | 4 | export default class SearchService extends BaseService { 5 | 6 | constructor(entity) { 7 | super(); 8 | this.url = '/api/' + entity; 9 | this.setupAPI(axios.defaults.baseURL); 10 | } 11 | 12 | public begin(phrase, page, perPage) { 13 | return this.get(this.url + `/?search=${phrase}&per_page=${perPage}&page=${page}`) 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /resources/app/services/UserService.ts: -------------------------------------------------------------------------------- 1 | import ModelService from "@/services/ModelService"; 2 | 3 | export default class UserService extends ModelService { 4 | 5 | constructor() { 6 | super(); 7 | this.url = '/users'; 8 | } 9 | 10 | public updateAvatar(id, payload) { 11 | const formData = new FormData(); 12 | formData.append("avatar", payload.avatar); 13 | return this.put(`/users/${id}/avatar`, formData); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /resources/app/stores/alert.js: -------------------------------------------------------------------------------- 1 | import {defineStore} from 'pinia'; 2 | 3 | export const useAlertStore = defineStore({ 4 | id: 'alert', 5 | state: () => { 6 | return { 7 | messages: [], 8 | type: null, 9 | } 10 | }, 11 | actions: { 12 | success(message) { 13 | this.clear(); 14 | this.push(message); 15 | this.type = 'success' 16 | }, 17 | error(message) { 18 | this.clear(); 19 | this.push(message); 20 | this.type = 'error' 21 | }, 22 | push(message) { 23 | if (Array.isArray(message) || (typeof message === 'object' && message != null)) { 24 | for (let i in message) { 25 | this.messages.push(message[i]); 26 | } 27 | } else { 28 | this.messages.push(message); 29 | } 30 | }, 31 | clear() { 32 | this.messages = []; 33 | this.type = null; 34 | }, 35 | isSuccess() { 36 | return this.type === 'success'; 37 | }, 38 | isError() { 39 | return this.type === 'error'; 40 | }, 41 | hasAlert() { 42 | return this.messages.length > 0 && this.type != null; 43 | }, 44 | hasMultiple() { 45 | return (Array.isArray(this.messages.length) && this.messages.length > 1) || ((typeof this.messages === 'object' && this.messages != null) &&Object.keys(this.messages).length > 1); 46 | }, 47 | } 48 | }); 49 | -------------------------------------------------------------------------------- /resources/app/stores/auth.js: -------------------------------------------------------------------------------- 1 | import router from "@/router"; 2 | import {defineStore} from 'pinia' 3 | import {getResponseError} from "@/helpers/api"; 4 | import {useAlertStore} from "@/stores/alert"; 5 | import AuthService from "@/services/AuthService"; 6 | import UserService from "@/services/UserService"; 7 | import {trans} from "@/helpers/i18n"; 8 | 9 | export const useAuthStore = defineStore("auth", { 10 | state: () => { 11 | return { 12 | user: null, 13 | error: null, 14 | }; 15 | }, 16 | actions: { 17 | async login(payload) { 18 | const authService = new AuthService(); 19 | const alertStore = useAlertStore(); 20 | try { 21 | const response = await authService.login(payload); 22 | this.user = response.data.user; 23 | this.setBrowserData(); 24 | alertStore.clear(); 25 | await router.push("/panel/dashboard"); 26 | await this.getCurrentUser(); 27 | } catch (error) { 28 | alertStore.error(getResponseError(error)); 29 | } 30 | }, 31 | async register(payload) { 32 | const authService = new AuthService(); 33 | const alertStore = useAlertStore(); 34 | try { 35 | const response = await authService.registerUser(payload); 36 | await router.push("/panel/dashboard"); 37 | alertStore.clear(); 38 | } catch (error) { 39 | alertStore.error(getResponseError(error)); 40 | } 41 | }, 42 | async getCurrentUser() { 43 | this.loading = true; 44 | const authService = new AuthService(); 45 | try { 46 | const response = await authService.getCurrentUser(); 47 | this.user = response.data.data; 48 | this.loading = false 49 | } catch (error) { 50 | this.loading = false 51 | this.user = null; 52 | this.error = getResponseError(error); 53 | } 54 | return this.user; 55 | }, 56 | updateAvatar(id, payload) { 57 | const alertStore = useAlertStore(); 58 | const userService = new UserService(); 59 | return new Promise((resolve, reject) => { 60 | return userService 61 | .updateAvatar(id, payload) 62 | .then((response) => { 63 | this.getCurrentUser().then(() => { 64 | alertStore.success(trans('global.phrases.file_uploaded')); 65 | resolve(response) 66 | }); 67 | }) 68 | .catch((err) => { 69 | alertStore.error(getResponseError(err)); 70 | reject(err) 71 | }) 72 | }) 73 | }, 74 | logout() { 75 | return new Promise((resolve, reject) => { 76 | const alertStore = useAlertStore(); 77 | const authService = new AuthService(); 78 | return authService 79 | .logout() 80 | .then((response) => { 81 | this.clearBrowserData(); 82 | this.user = null; 83 | if (router.currentRoute.name !== "login") { 84 | router.push({path: "/login"}); 85 | console.log('logout...'); 86 | } 87 | resolve(response) 88 | }) 89 | .catch((err) => { 90 | alertStore.error(getResponseError(err)); 91 | reject(err) 92 | }) 93 | }); 94 | }, 95 | hasBrowserData() { 96 | let data = window.localStorage.getItem('currentUser'); 97 | return !!data; 98 | }, 99 | setBrowserData() { 100 | window.localStorage.setItem('currentUser', JSON.stringify(this.user)) 101 | }, 102 | clearBrowserData() { 103 | window.localStorage.removeItem('currentUser'); 104 | }, 105 | hasAbilities(abilities) { 106 | return this.user && this.user.hasOwnProperty('abilities') && !!this.user.abilities.find((ab) => { 107 | if (ab.name === '*') { 108 | return true 109 | } 110 | if (typeof abilities === 'string') { 111 | return ab.name === abilities 112 | } 113 | return !!abilities.find((p) => { 114 | return ab.name === p 115 | }) 116 | }) 117 | }, 118 | 119 | hasAllAbilities(abilities) { 120 | let isAvailable = true 121 | if (this.user && this.user.hasOwnProperty('abilities')) { 122 | this.user.abilities.filter((ab) => { 123 | let hasContain = !!abilities.find((p) => { 124 | return ab.name === p 125 | }) 126 | if (!hasContain) { 127 | isAvailable = false 128 | } 129 | }) 130 | } 131 | 132 | return isAvailable 133 | }, 134 | }, 135 | getters: { 136 | isAdmin: (state) => { 137 | return state.user ? state.user.is_admin : false; 138 | }, 139 | loggedIn: (state) => { 140 | return !!state.user; 141 | }, 142 | guest: (state) => { 143 | return !state.hasBrowserData(); 144 | }, 145 | } 146 | }); 147 | -------------------------------------------------------------------------------- /resources/app/stores/global.js: -------------------------------------------------------------------------------- 1 | import {defineStore} from 'pinia'; 2 | 3 | export const useGlobalStateStore = defineStore({ 4 | id: 'global_state', 5 | state: () => { 6 | return { 7 | loadingElements: {}, 8 | isUILoading: false, 9 | } 10 | }, 11 | actions: { 12 | setUILoading(isLoading) { 13 | this.isUILoading = isLoading; 14 | }, 15 | isUILoading() { 16 | return this.isUILoading; 17 | }, 18 | setElementLoading(element, isLoading) { 19 | if (!element || !element.length) { 20 | return; 21 | } 22 | this.loadingElements[element] = isLoading; 23 | this.setUILoading(isLoading); 24 | } 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /resources/app/stores/index.js: -------------------------------------------------------------------------------- 1 | export * from './alert'; 2 | export * from './auth'; 3 | export * from './global'; 4 | -------------------------------------------------------------------------------- /resources/app/stub/abilities.js: -------------------------------------------------------------------------------- 1 | const abilities = { 2 | CREATE_USER: 'create_user', 3 | EDIT_USER: 'edit_user', 4 | DELETE_USER: 'delete_user', 5 | VIEW_USER: 'view_user', 6 | LIST_USER: 'list_user', 7 | } 8 | 9 | export default abilities; 10 | -------------------------------------------------------------------------------- /resources/app/views/components/Alert.vue: -------------------------------------------------------------------------------- 1 | 35 | 36 | 88 | -------------------------------------------------------------------------------- /resources/app/views/components/Badge.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 50 | -------------------------------------------------------------------------------- /resources/app/views/components/Form.vue: -------------------------------------------------------------------------------- 1 | 11 | 45 | -------------------------------------------------------------------------------- /resources/app/views/components/Modal.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 67 | -------------------------------------------------------------------------------- /resources/app/views/components/Panel.vue: -------------------------------------------------------------------------------- 1 | 18 | 19 | 57 | -------------------------------------------------------------------------------- /resources/app/views/components/filters/Filters.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 34 | -------------------------------------------------------------------------------- /resources/app/views/components/filters/FiltersCol.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 15 | 16 | 34 | -------------------------------------------------------------------------------- /resources/app/views/components/filters/FiltersRow.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /resources/app/views/components/icons/Avatar.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /resources/app/views/components/icons/Icon.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 28 | -------------------------------------------------------------------------------- /resources/app/views/components/icons/Spinner.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | 42 | -------------------------------------------------------------------------------- /resources/app/views/components/input/Button.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 92 | -------------------------------------------------------------------------------- /resources/app/views/components/input/Dropdown.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 129 | 130 | 131 | 143 | -------------------------------------------------------------------------------- /resources/app/views/components/input/TextInput.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 90 | -------------------------------------------------------------------------------- /resources/app/views/layouts/Auth.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 32 | -------------------------------------------------------------------------------- /resources/app/views/layouts/Page.vue: -------------------------------------------------------------------------------- 1 | 44 | 45 | 99 | -------------------------------------------------------------------------------- /resources/app/views/pages/auth/forgot-password/Form.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 54 | -------------------------------------------------------------------------------- /resources/app/views/pages/auth/forgot-password/Main.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 41 | -------------------------------------------------------------------------------- /resources/app/views/pages/auth/login/Form.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 53 | -------------------------------------------------------------------------------- /resources/app/views/pages/auth/login/Main.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | 41 | -------------------------------------------------------------------------------- /resources/app/views/pages/auth/register/Form.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 65 | -------------------------------------------------------------------------------- /resources/app/views/pages/auth/register/Main.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 35 | -------------------------------------------------------------------------------- /resources/app/views/pages/auth/reset-password/Form.vue: -------------------------------------------------------------------------------- 1 | 23 | 24 | 73 | -------------------------------------------------------------------------------- /resources/app/views/pages/auth/reset-password/Main.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 35 | -------------------------------------------------------------------------------- /resources/app/views/pages/private/dashboard/Main.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 29 | -------------------------------------------------------------------------------- /resources/app/views/pages/private/profile/Main.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 73 | -------------------------------------------------------------------------------- /resources/app/views/pages/private/profile/partials/FormAvatar.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 56 | -------------------------------------------------------------------------------- /resources/app/views/pages/private/profile/partials/FormGeneral.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 68 | -------------------------------------------------------------------------------- /resources/app/views/pages/private/profile/partials/FormPassword.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 65 | -------------------------------------------------------------------------------- /resources/app/views/pages/private/profile/partials/Overview.vue: -------------------------------------------------------------------------------- 1 | 35 | 36 | 82 | -------------------------------------------------------------------------------- /resources/app/views/pages/private/users/Create.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 107 | 108 | 111 | -------------------------------------------------------------------------------- /resources/app/views/pages/private/users/Edit.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 123 | 124 | 127 | -------------------------------------------------------------------------------- /resources/app/views/pages/shared/404/Main.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 29 | -------------------------------------------------------------------------------- /resources/styles/main.scss: -------------------------------------------------------------------------------- 1 | @import "tailwind"; 2 | @import "fork-awesome"; 3 | -------------------------------------------------------------------------------- /resources/styles/tailwind.scss: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | @layer base { 6 | 7 | body { 8 | @apply bg-gray-50; 9 | } 10 | .base-link { 11 | @apply text-blue-400; 12 | @apply hover:text-blue-500; 13 | @apply hover:underline; 14 | @apply transition; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /resources/views/index.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{env('APP_NAME')}} 8 | 9 | @vite(['resources/styles/main.scss', 'resources/app/main.js']) 10 | 11 | 25 | 26 | 27 | 28 | 31 | 32 |
33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | group(function () { 23 | 24 | /** 25 | * Auth related 26 | */ 27 | Route::get('/users/auth', AuthController::class); 28 | 29 | /** 30 | * Users 31 | */ 32 | Route::put('/users/{user}/avatar', [UserController::class, 'updateAvatar']); 33 | Route::resource('users', UserController::class); 34 | 35 | /** 36 | * Roles 37 | */ 38 | Route::get('/roles/search', [RoleController::class, 'search'])->middleware('throttle:400,1'); 39 | }); 40 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 19 | })->purpose('Display an inspiring quote'); 20 | 21 | Artisan::command('logs:clear', function () { 22 | exec('rm '.storage_path('logs/*.log')); 23 | $this->comment('Logs have been cleared!'); 24 | })->describe('Clear log files'); 25 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | where('path', '(.*)'); 18 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !public/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | compiled.php 2 | config.php 3 | down 4 | events.scanned.php 5 | maintenance.php 6 | routes.php 7 | routes.scanned.php 8 | schedule-* 9 | services.json 10 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | const colors = require('tailwindcss/colors'); 2 | 3 | /** @type {import('tailwindcss').Config} */ 4 | export default { 5 | content: ["./resources/app/**/*.html", "./resources/app/**/*.vue"], 6 | theme: { 7 | extend: { 8 | colors: { 9 | theme: colors.teal, 10 | danger: colors.red 11 | } 12 | } 13 | }, 14 | variants: { 15 | extend: {}, 16 | }, 17 | plugins: [ 18 | require('@tailwindcss/forms'), 19 | require('@tailwindcss/typography'), 20 | require('@tailwindcss/aspect-ratio') 21 | ], 22 | }; 23 | -------------------------------------------------------------------------------- /tests/Feature/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 16 | 17 | $response->assertStatus(200); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | 4 | "baseUrl": ".", 5 | "paths": { 6 | "@/*": ["./resources/app/*"] 7 | }, 8 | 9 | "module": "ESNext", 10 | "moduleResolution": "Node", 11 | "resolveJsonModule": true, 12 | "useDefineForClassFields": true, 13 | 14 | // Required in Vue projects 15 | "jsx": "preserve", 16 | 17 | // `"noImplicitThis": true` is part of `strict` 18 | // Added again here in case some users decide to disable `strict`. 19 | // This enables stricter inference for data properties on `this`. 20 | "noImplicitThis": true, 21 | "strict": false, 22 | 23 | // Required in Vite 24 | "isolatedModules": true, 25 | // For `