├── .editorconfig ├── .env.example ├── .gitattributes ├── .gitignore ├── README.md ├── app ├── Enum │ ├── PermissionsEnum.php │ └── RolesEnum.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ ├── AuthenticatedSessionController.php │ │ │ ├── ConfirmablePasswordController.php │ │ │ ├── EmailVerificationNotificationController.php │ │ │ ├── EmailVerificationPromptController.php │ │ │ ├── NewPasswordController.php │ │ │ ├── PasswordController.php │ │ │ ├── PasswordResetLinkController.php │ │ │ ├── RegisteredUserController.php │ │ │ └── VerifyEmailController.php │ │ ├── CommentController.php │ │ ├── Controller.php │ │ ├── FeatureController.php │ │ ├── ProfileController.php │ │ ├── UpvoteController.php │ │ └── UserController.php │ ├── Middleware │ │ └── HandleInertiaRequests.php │ ├── Requests │ │ ├── Auth │ │ │ └── LoginRequest.php │ │ └── ProfileUpdateRequest.php │ └── Resources │ │ ├── AuthUserResource.php │ │ ├── FeatureListResource.php │ │ ├── FeatureResource.php │ │ └── UserResource.php ├── Models │ ├── Comment.php │ ├── Feature.php │ ├── Upvote.php │ └── User.php └── Providers │ └── AppServiceProvider.php ├── artisan ├── bootstrap ├── app.php ├── cache │ └── .gitignore └── providers.php ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── cache.php ├── database.php ├── filesystems.php ├── logging.php ├── mail.php ├── permission.php ├── queue.php ├── services.php └── session.php ├── database ├── .gitignore ├── factories │ ├── FeatureFactory.php │ └── 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 │ ├── 2024_11_01_163644_create_permission_tables.php │ ├── 2024_11_01_170947_create_features_table.php │ ├── 2024_11_01_171010_create_upvotes_table.php │ └── 2024_11_01_171020_create_comments_table.php └── seeders │ └── DatabaseSeeder.php ├── package-lock.json ├── package.json ├── phpunit.xml ├── postcss.config.js ├── public ├── .htaccess ├── favicon.ico ├── index.php └── robots.txt ├── resources ├── css │ └── app.css ├── js │ ├── Components │ │ ├── ApplicationLogo.tsx │ │ ├── Checkbox.tsx │ │ ├── CommentItem.tsx │ │ ├── DangerButton.tsx │ │ ├── Dropdown.tsx │ │ ├── FeatureActionsDropdown.tsx │ │ ├── FeatureItem.tsx │ │ ├── FeatureUpvoteDownvote.tsx │ │ ├── InputError.tsx │ │ ├── InputLabel.tsx │ │ ├── Modal.tsx │ │ ├── NavLink.tsx │ │ ├── NewCommentForm.tsx │ │ ├── PrimaryButton.tsx │ │ ├── Radio.tsx │ │ ├── ResponsiveNavLink.tsx │ │ ├── SecondaryButton.tsx │ │ ├── TextAreaInput.tsx │ │ └── TextInput.tsx │ ├── Layouts │ │ ├── AuthenticatedLayout.tsx │ │ └── GuestLayout.tsx │ ├── Pages │ │ ├── Auth │ │ │ ├── ConfirmPassword.tsx │ │ │ ├── ForgotPassword.tsx │ │ │ ├── Login.tsx │ │ │ ├── Register.tsx │ │ │ ├── ResetPassword.tsx │ │ │ └── VerifyEmail.tsx │ │ ├── Dashboard.tsx │ │ ├── Feature │ │ │ ├── Create.tsx │ │ │ ├── Edit.tsx │ │ │ ├── Index.tsx │ │ │ └── Show.tsx │ │ ├── Profile │ │ │ ├── Edit.tsx │ │ │ └── Partials │ │ │ │ ├── DeleteUserForm.tsx │ │ │ │ ├── UpdatePasswordForm.tsx │ │ │ │ └── UpdateProfileInformationForm.tsx │ │ ├── User │ │ │ ├── Edit.tsx │ │ │ └── Index.tsx │ │ └── Welcome.tsx │ ├── app.tsx │ ├── bootstrap.ts │ ├── helpers.ts │ ├── ssr.tsx │ └── types │ │ ├── global.d.ts │ │ ├── index.d.ts │ │ └── vite-env.d.ts └── views │ └── app.blade.php ├── routes ├── auth.php ├── console.php └── web.php ├── storage ├── app │ ├── .gitignore │ ├── private │ │ └── .gitignore │ └── public │ │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ ├── .gitignore │ │ └── data │ │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tailwind.config.js ├── tests ├── Feature │ ├── Auth │ │ ├── AuthenticationTest.php │ │ ├── EmailVerificationTest.php │ │ ├── PasswordConfirmationTest.php │ │ ├── PasswordResetTest.php │ │ ├── PasswordUpdateTest.php │ │ └── RegistrationTest.php │ ├── ExampleTest.php │ └── ProfileTest.php ├── Pest.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 | [*.{ts,tsx,js,jsx,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 | PHP_CLI_SERVER_WORKERS=4 16 | 17 | BCRYPT_ROUNDS=12 18 | 19 | LOG_CHANNEL=stack 20 | LOG_STACK=single 21 | LOG_DEPRECATIONS_CHANNEL=null 22 | LOG_LEVEL=debug 23 | 24 | DB_CONNECTION=sqlite 25 | # DB_HOST=127.0.0.1 26 | # DB_PORT=3306 27 | # DB_DATABASE=laravel 28 | # DB_USERNAME=root 29 | # DB_PASSWORD= 30 | 31 | SESSION_DRIVER=database 32 | SESSION_LIFETIME=120 33 | SESSION_ENCRYPT=false 34 | SESSION_PATH=/ 35 | SESSION_DOMAIN=null 36 | 37 | BROADCAST_CONNECTION=log 38 | FILESYSTEM_DISK=local 39 | QUEUE_CONNECTION=database 40 | 41 | CACHE_STORE=database 42 | CACHE_PREFIX= 43 | 44 | MEMCACHED_HOST=127.0.0.1 45 | 46 | REDIS_CLIENT=phpredis 47 | REDIS_HOST=127.0.0.1 48 | REDIS_PASSWORD=null 49 | REDIS_PORT=6379 50 | 51 | MAIL_MAILER=log 52 | MAIL_HOST=127.0.0.1 53 | MAIL_PORT=2525 54 | MAIL_USERNAME=null 55 | MAIL_PASSWORD=null 56 | MAIL_ENCRYPTION=null 57 | MAIL_FROM_ADDRESS="hello@example.com" 58 | MAIL_FROM_NAME="${APP_NAME}" 59 | 60 | AWS_ACCESS_KEY_ID= 61 | AWS_SECRET_ACCESS_KEY= 62 | AWS_DEFAULT_REGION=us-east-1 63 | AWS_BUCKET= 64 | AWS_USE_PATH_STYLE_ENDPOINT=false 65 | 66 | VITE_APP_NAME="${APP_NAME}" 67 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 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 | /bootstrap/ssr 3 | /node_modules 4 | /public/build 5 | /public/hot 6 | /public/storage 7 | /storage/*.key 8 | /storage/pail 9 | /vendor 10 | .env 11 | .env.backup 12 | .env.production 13 | .phpactor.json 14 | .phpunit.result.cache 15 | Homestead.json 16 | Homestead.yaml 17 | auth.json 18 | npm-debug.log 19 | yarn-error.log 20 | /.fleet 21 | /.idea 22 | /.vscode 23 | /.zed 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel, React with Inertia v2 with TypeScript and SSR 2 | 3 | Full Stack starter kit with Laravel, React with TypeScript, Inertia V2 with Server Side Rendering and with roles and permissions using [Spatie Laravel Permission](https://spatie.be/docs/laravel-permission/v6/installation-laravel) package. 4 | 5 | > To see every step how I created this project and deployed it on [larareact.com](https://larareact.com) with server side rendering check the following [YouTube Tutorial](https://youtu.be/lqKbDEBa2B0) 6 | 7 | ## Demo 8 | 9 | https://larareact.com 10 | 11 | **Admin User** 12 | ``` 13 | Email: admin@example.com 14 | Password: password 15 | ``` 16 | 17 | **Commenter User** 18 | ``` 19 | Email: commenter@example.com 20 | Password: password 21 | ``` 22 | 23 | **Regular User** 24 | ``` 25 | Email: user@example.com 26 | Password: password 27 | ``` 28 | 29 | ## Local Setup 30 | 31 | > [!TIP] 32 | > Make sure you have installed php, composer, node.js and the following commands are available in terminal. `php`, `node`, `npm`, `composer`. 33 | 34 | 1. Clone the project 35 | 2. Go to the project's root directory from terminal 36 | 3. Copy `.env.example` into `.env` file (`cp .env.example .env`) 37 | 4. Open and adjust your `.env` parameters 38 | 5. Run `composer install` 39 | 6. Run `php artisan key:generate --ansi` 40 | 7. Execute migrations with seed data: `php artisan migrate --seed` 41 | 8. Run `npm install` 42 | 9. Run `composer run dev` for local development 43 | 44 | ## Setup SSR 45 | Follow the steps above including step 8, after which 46 | 1. Open terminal and execute `npm run build` to build react assets 47 | 2. Then start artisan server: `php artisan serve` 48 | 3. Open another terminal and execute `php artisan inertia:start-ssr` to start server side rendering server 49 | 50 | ## Deploy on Production 51 | 52 | To see every step how to setup the project on production, assign domain to it and setup supervisor to start and monitor server side sendering server check the following [YouTube tutorial](https://youtu.be/lqKbDEBa2B0). 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /app/Enum/PermissionsEnum.php: -------------------------------------------------------------------------------- 1 | value => 'Admin', 15 | self::Commenter->value => 'Commenter', 16 | self::User->value => 'User', 17 | ]; 18 | } 19 | 20 | public function label() 21 | { 22 | return match($this) { 23 | self::Admin => 'Admin', 24 | self::User => 'User', 25 | self::Commenter => 'Commenter', 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/AuthenticatedSessionController.php: -------------------------------------------------------------------------------- 1 | Route::has('password.request'), 23 | 'status' => session('status'), 24 | ]); 25 | } 26 | 27 | /** 28 | * Handle an incoming authentication request. 29 | */ 30 | public function store(LoginRequest $request): RedirectResponse 31 | { 32 | $request->authenticate(); 33 | 34 | $request->session()->regenerate(); 35 | 36 | return redirect()->intended(route('dashboard', absolute: false)); 37 | } 38 | 39 | /** 40 | * Destroy an authenticated session. 41 | */ 42 | public function destroy(Request $request): RedirectResponse 43 | { 44 | Auth::guard('web')->logout(); 45 | 46 | $request->session()->invalidate(); 47 | 48 | $request->session()->regenerateToken(); 49 | 50 | return redirect('/'); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ConfirmablePasswordController.php: -------------------------------------------------------------------------------- 1 | validate([ 29 | 'email' => $request->user()->email, 30 | 'password' => $request->password, 31 | ])) { 32 | throw ValidationException::withMessages([ 33 | 'password' => __('auth.password'), 34 | ]); 35 | } 36 | 37 | $request->session()->put('auth.password_confirmed_at', time()); 38 | 39 | return redirect()->intended(route('dashboard', absolute: false)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/EmailVerificationNotificationController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail()) { 17 | return redirect()->intended(route('dashboard', absolute: false)); 18 | } 19 | 20 | $request->user()->sendEmailVerificationNotification(); 21 | 22 | return back()->with('status', 'verification-link-sent'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/EmailVerificationPromptController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail() 19 | ? redirect()->intended(route('dashboard', absolute: false)) 20 | : Inertia::render('Auth/VerifyEmail', ['status' => session('status')]); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/NewPasswordController.php: -------------------------------------------------------------------------------- 1 | $request->email, 26 | 'token' => $request->route('token'), 27 | ]); 28 | } 29 | 30 | /** 31 | * Handle an incoming new password request. 32 | * 33 | * @throws \Illuminate\Validation\ValidationException 34 | */ 35 | public function store(Request $request): RedirectResponse 36 | { 37 | $request->validate([ 38 | 'token' => 'required', 39 | 'email' => 'required|email', 40 | 'password' => ['required', 'confirmed', Rules\Password::defaults()], 41 | ]); 42 | 43 | // Here we will attempt to reset the user's password. If it is successful we 44 | // will update the password on an actual user model and persist it to the 45 | // database. Otherwise we will parse the error and return the response. 46 | $status = Password::reset( 47 | $request->only('email', 'password', 'password_confirmation', 'token'), 48 | function ($user) use ($request) { 49 | $user->forceFill([ 50 | 'password' => Hash::make($request->password), 51 | 'remember_token' => Str::random(60), 52 | ])->save(); 53 | 54 | event(new PasswordReset($user)); 55 | } 56 | ); 57 | 58 | // If the password was successfully reset, we will redirect the user back to 59 | // the application's home authenticated view. If there is an error we can 60 | // redirect them back to where they came from with their error message. 61 | if ($status == Password::PASSWORD_RESET) { 62 | return redirect()->route('login')->with('status', __($status)); 63 | } 64 | 65 | throw ValidationException::withMessages([ 66 | 'email' => [trans($status)], 67 | ]); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordController.php: -------------------------------------------------------------------------------- 1 | validate([ 19 | 'current_password' => ['required', 'current_password'], 20 | 'password' => ['required', Password::defaults(), 'confirmed'], 21 | ]); 22 | 23 | $request->user()->update([ 24 | 'password' => Hash::make($validated['password']), 25 | ]); 26 | 27 | return back(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordResetLinkController.php: -------------------------------------------------------------------------------- 1 | session('status'), 22 | ]); 23 | } 24 | 25 | /** 26 | * Handle an incoming password reset link request. 27 | * 28 | * @throws \Illuminate\Validation\ValidationException 29 | */ 30 | public function store(Request $request): RedirectResponse 31 | { 32 | $request->validate([ 33 | 'email' => 'required|email', 34 | ]); 35 | 36 | // We will send the password reset link to this user. Once we have attempted 37 | // to send the link, we will examine the response then see the message we 38 | // need to show to the user. Finally, we'll send out a proper response. 39 | $status = Password::sendResetLink( 40 | $request->only('email') 41 | ); 42 | 43 | if ($status == Password::RESET_LINK_SENT) { 44 | return back()->with('status', __($status)); 45 | } 46 | 47 | throw ValidationException::withMessages([ 48 | 'email' => [trans($status)], 49 | ]); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisteredUserController.php: -------------------------------------------------------------------------------- 1 | validate([ 35 | 'name' => 'required|string|max:255', 36 | 'email' => 'required|string|lowercase|email|max:255|unique:'.User::class, 37 | 'password' => ['required', 'confirmed', Rules\Password::defaults()], 38 | ]); 39 | 40 | $user = User::create([ 41 | 'name' => $request->name, 42 | 'email' => $request->email, 43 | 'password' => Hash::make($request->password), 44 | ]); 45 | 46 | $user->assignRole(RolesEnum::User->value); 47 | 48 | event(new Registered($user)); 49 | 50 | Auth::login($user); 51 | 52 | return redirect(route('dashboard', absolute: false)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/VerifyEmailController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail()) { 18 | return redirect()->intended(route('dashboard', absolute: false).'?verified=1'); 19 | } 20 | 21 | if ($request->user()->markEmailAsVerified()) { 22 | event(new Verified($request->user())); 23 | } 24 | 25 | return redirect()->intended(route('dashboard', absolute: false).'?verified=1'); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Http/Controllers/CommentController.php: -------------------------------------------------------------------------------- 1 | validate([ 15 | 'comment' => 'required' 16 | ]); 17 | 18 | $data['feature_id'] = $feature->id; 19 | $data['user_id'] = Auth::id(); 20 | Comment::create($data); 21 | 22 | return to_route('feature.show', $feature); 23 | } 24 | 25 | public function destroy(Comment $comment) 26 | { 27 | if ($comment->user_id !== Auth::id()) { 28 | abort(403); 29 | } 30 | $featureId = $comment->feature_id; 31 | $comment->delete(); 32 | 33 | return to_route('feature.show', $featureId); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | withCount(['upvotes as upvote_count' => function ($query) { 26 | $query->select(DB::raw('SUM(CASE WHEN upvote = 1 THEN 1 ELSE -1 END)')); 27 | }]) 28 | ->withExists([ 29 | 'upvotes as user_has_upvoted' => function ($query) use ($currentUserId) { 30 | $query->where('user_id', $currentUserId) 31 | ->where('upvote', 1); 32 | }, 33 | 'upvotes as user_has_downvoted' => function ($query) use ($currentUserId) { 34 | $query->where('user_id', $currentUserId) 35 | ->where('upvote', 0); 36 | } 37 | ]) 38 | ->paginate(); 39 | 40 | return Inertia::render('Feature/Index', [ 41 | 'features' => FeatureListResource::collection($paginated) 42 | ]); 43 | } 44 | 45 | /** 46 | * Show the form for creating a new resource. 47 | */ 48 | public function create() 49 | { 50 | return Inertia::render('Feature/Create'); 51 | } 52 | 53 | /** 54 | * Store a newly created resource in storage. 55 | */ 56 | public function store(Request $request) 57 | { 58 | $data = $request->validate([ 59 | 'name' => ['required', 'string'], 60 | 'description' => ['nullable', 'string'], 61 | ]); 62 | $data['user_id'] = auth()->id(); 63 | 64 | Feature::create($data); 65 | 66 | return to_route('feature.index')->with('success', 'Feature created successfully.'); 67 | } 68 | 69 | /** 70 | * Display the specified resource. 71 | */ 72 | public function show(Feature $feature) 73 | { 74 | $feature->upvote_count = Upvote::where('feature_id', $feature->id) 75 | ->sum(DB::raw('CASE WHEN upvote = 1 THEN 1 ELSE -1 END')); 76 | 77 | $feature->user_has_upvoted = Upvote::where('feature_id', $feature->id) 78 | ->where('user_id', Auth::id()) 79 | ->where('upvote', 1) 80 | ->exists(); 81 | $feature->user_has_downvoted = Upvote::where('feature_id', $feature->id) 82 | ->where('user_id', Auth::id()) 83 | ->where('upvote', 0) 84 | ->exists(); 85 | 86 | return Inertia::render('Feature/Show', [ 87 | 'feature' => new FeatureResource($feature), 88 | 'comments' => Inertia::defer(function() use ($feature) { 89 | return $feature->comments->map(function ($comment) { 90 | return [ 91 | 'id' => $comment->id, 92 | 'comment' => $comment->comment, 93 | 'created_at' => $comment->created_at->format('Y-m-d H:i:s'), 94 | 'user' => new UserResource($comment->user), 95 | ]; 96 | }); 97 | }) 98 | ]); 99 | } 100 | 101 | /** 102 | * Show the form for editing the specified resource. 103 | */ 104 | public function edit(Feature $feature) 105 | { 106 | return Inertia::render('Feature/Edit', [ 107 | 'feature' => new FeatureResource($feature) 108 | ]); 109 | } 110 | 111 | /** 112 | * Update the specified resource in storage. 113 | */ 114 | public function update(Request $request, Feature $feature) 115 | { 116 | $data = $request->validate([ 117 | 'name' => ['required', 'string'], 118 | 'description' => ['nullable', 'string'], 119 | ]); 120 | 121 | $feature->update($data); 122 | 123 | return to_route('feature.index')->with('success', 'Feature updated successfully.'); 124 | } 125 | 126 | /** 127 | * Remove the specified resource from storage. 128 | */ 129 | public function destroy(Feature $feature) 130 | { 131 | $feature->delete(); 132 | 133 | return to_route('feature.index')->with('success', 'Feature deleted successfully.'); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /app/Http/Controllers/ProfileController.php: -------------------------------------------------------------------------------- 1 | $request->user() instanceof MustVerifyEmail, 23 | 'status' => session('status'), 24 | ]); 25 | } 26 | 27 | /** 28 | * Update the user's profile information. 29 | */ 30 | public function update(ProfileUpdateRequest $request): RedirectResponse 31 | { 32 | $request->user()->fill($request->validated()); 33 | 34 | if ($request->user()->isDirty('email')) { 35 | $request->user()->email_verified_at = null; 36 | } 37 | 38 | $request->user()->save(); 39 | 40 | return Redirect::route('profile.edit'); 41 | } 42 | 43 | /** 44 | * Delete the user's account. 45 | */ 46 | public function destroy(Request $request): RedirectResponse 47 | { 48 | $request->validate([ 49 | 'password' => ['required', 'current_password'], 50 | ]); 51 | 52 | $user = $request->user(); 53 | 54 | Auth::logout(); 55 | 56 | $user->delete(); 57 | 58 | $request->session()->invalidate(); 59 | $request->session()->regenerateToken(); 60 | 61 | return Redirect::to('/'); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/Http/Controllers/UpvoteController.php: -------------------------------------------------------------------------------- 1 | validate([ 14 | 'upvote' => ['required', 'boolean'] 15 | ]); 16 | 17 | Upvote::updateOrCreate( 18 | ['feature_id' => $feature->id, 'user_id' => auth()->id()], 19 | ['upvote' => $data['upvote']] 20 | ); 21 | 22 | return back(); 23 | } 24 | 25 | public function destroy(Feature $feature) 26 | { 27 | $feature->upvotes()->where('user_id', auth()->id())->delete(); 28 | 29 | return back(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/Http/Controllers/UserController.php: -------------------------------------------------------------------------------- 1 | AuthUserResource::collection(User::all())->collection->toArray() 21 | ]); 22 | } 23 | 24 | /** 25 | * Show the form for editing the specified resource. 26 | */ 27 | public function edit(User $user) 28 | { 29 | return Inertia::render('User/Edit', [ 30 | 'user' => new AuthUserResource($user), 31 | 'roles' => Role::all(), 32 | 'roleLabels' => RolesEnum::labels() 33 | ]); 34 | } 35 | 36 | /** 37 | * Update the specified resource in storage. 38 | */ 39 | public function update(Request $request, User $user) 40 | { 41 | $data = $request->validate([ 42 | 'roles' => ['required', 'array'], 43 | ]); 44 | 45 | $user->syncRoles($data['roles']); 46 | 47 | return back()->with('success', 'Roles updated successfully.'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/Http/Middleware/HandleInertiaRequests.php: -------------------------------------------------------------------------------- 1 | 31 | */ 32 | public function share(Request $request): array 33 | { 34 | $user = $request->user(); 35 | return [ 36 | ...parent::share($request), 37 | 'auth' => [ 38 | 'user' => $user ? new AuthUserResource($user) : null, 39 | ], 40 | 'ziggy' => fn () => [ 41 | ...(new Ziggy)->toArray(), 42 | 'location' => $request->url(), 43 | ], 44 | 'success' => session('success') 45 | ]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/Http/Requests/Auth/LoginRequest.php: -------------------------------------------------------------------------------- 1 | 26 | */ 27 | public function rules(): array 28 | { 29 | return [ 30 | 'email' => ['required', 'string', 'email'], 31 | 'password' => ['required', 'string'], 32 | ]; 33 | } 34 | 35 | /** 36 | * Attempt to authenticate the request's credentials. 37 | * 38 | * @throws \Illuminate\Validation\ValidationException 39 | */ 40 | public function authenticate(): void 41 | { 42 | $this->ensureIsNotRateLimited(); 43 | 44 | if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { 45 | RateLimiter::hit($this->throttleKey()); 46 | 47 | throw ValidationException::withMessages([ 48 | 'email' => trans('auth.failed'), 49 | ]); 50 | } 51 | 52 | RateLimiter::clear($this->throttleKey()); 53 | } 54 | 55 | /** 56 | * Ensure the login request is not rate limited. 57 | * 58 | * @throws \Illuminate\Validation\ValidationException 59 | */ 60 | public function ensureIsNotRateLimited(): void 61 | { 62 | if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { 63 | return; 64 | } 65 | 66 | event(new Lockout($this)); 67 | 68 | $seconds = RateLimiter::availableIn($this->throttleKey()); 69 | 70 | throw ValidationException::withMessages([ 71 | 'email' => trans('auth.throttle', [ 72 | 'seconds' => $seconds, 73 | 'minutes' => ceil($seconds / 60), 74 | ]), 75 | ]); 76 | } 77 | 78 | /** 79 | * Get the rate limiting throttle key for the request. 80 | */ 81 | public function throttleKey(): string 82 | { 83 | return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip()); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /app/Http/Requests/ProfileUpdateRequest.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | public function rules(): array 17 | { 18 | return [ 19 | 'name' => ['required', 'string', 'max:255'], 20 | 'email' => [ 21 | 'required', 22 | 'string', 23 | 'lowercase', 24 | 'email', 25 | 'max:255', 26 | Rule::unique(User::class)->ignore($this->user()->id), 27 | ], 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Resources/AuthUserResource.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | public function toArray(Request $request): array 18 | { 19 | return [ 20 | 'id' => $this->id, 21 | 'name' => $this->name, 22 | 'created_at' => $this->created_at->format('Y-m-d H:i:s'), 23 | 'email' => $this->email, 24 | 'email_verified_at' => $this->email_verified_at, 25 | 'permissions' => $this->getAllPermissions() 26 | ->map(function ($permission) { 27 | return $permission->name; 28 | }), 29 | 'roles' => $this->getRoleNames() 30 | ]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Resources/FeatureListResource.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | public function toArray(Request $request): array 18 | { 19 | return [ 20 | 'id' => $this->id, 21 | 'name' => $this->name, 22 | 'description' => $this->description, 23 | 'user' => new UserResource($this->user), 24 | 'created_at' => $this->created_at->format('Y-m-d H:i:s'), 25 | 'upvote_count' => $this->upvote_count ?: 0, 26 | 'user_has_upvoted' => (bool)$this->user_has_upvoted, 27 | 'user_has_downvoted' => (bool)$this->user_has_downvoted, 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Resources/FeatureResource.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | public function toArray(Request $request): array 18 | { 19 | return [ 20 | 'id' => $this->id, 21 | 'name' => $this->name, 22 | 'description' => $this->description, 23 | 'user' => new UserResource($this->user), 24 | 'created_at' => $this->created_at->format('Y-m-d H:i:s'), 25 | 'upvote_count' => $this->upvote_count ?: 0, 26 | 'user_has_upvoted' => (bool)$this->user_has_upvoted, 27 | 'user_has_downvoted' => (bool)$this->user_has_downvoted, 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Resources/UserResource.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | public function toArray(Request $request): array 18 | { 19 | return [ 20 | 'id' => $this->id, 21 | 'name' => $this->name, 22 | 'email' => $this->email, 23 | ]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/Models/Comment.php: -------------------------------------------------------------------------------- 1 | belongsTo(User::class); 15 | } 16 | 17 | public function feature(): BelongsTo 18 | { 19 | return $this->belongsTo(Feature::class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/Models/Feature.php: -------------------------------------------------------------------------------- 1 | hasMany(Upvote::class); 19 | } 20 | 21 | public function comments(): HasMany 22 | { 23 | return $this->hasMany(Comment::class)->latest(); 24 | } 25 | 26 | public function user(): BelongsTo 27 | { 28 | return $this->belongsTo(User::class); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Models/Upvote.php: -------------------------------------------------------------------------------- 1 | belongsTo(Feature::class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/Models/User.php: -------------------------------------------------------------------------------- 1 | */ 16 | use HasFactory, Notifiable, HasRoles; 17 | 18 | /** 19 | * The attributes that are mass assignable. 20 | * 21 | * @var array 22 | */ 23 | protected $fillable = [ 24 | 'name', 25 | 'email', 26 | 'password', 27 | ]; 28 | 29 | /** 30 | * The attributes that should be hidden for serialization. 31 | * 32 | * @var array 33 | */ 34 | protected $hidden = [ 35 | 'password', 36 | 'remember_token', 37 | ]; 38 | 39 | /** 40 | * Get the attributes that should be cast. 41 | * 42 | * @return array 43 | */ 44 | protected function casts(): array 45 | { 46 | return [ 47 | 'email_verified_at' => 'datetime', 48 | 'password' => 'hashed', 49 | ]; 50 | } 51 | 52 | public function features(): HasMany 53 | { 54 | return $this->hasMany(Feature::class); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | handleCommand(new ArgvInput); 14 | 15 | exit($status); 16 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | withRouting( 9 | web: __DIR__.'/../routes/web.php', 10 | commands: __DIR__.'/../routes/console.php', 11 | health: '/up', 12 | ) 13 | ->withMiddleware(function (Middleware $middleware) { 14 | $middleware->web(append: [ 15 | \App\Http\Middleware\HandleInertiaRequests::class, 16 | \Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class, 17 | ]); 18 | 19 | $middleware->alias([ 20 | 'role' => \Spatie\Permission\Middleware\RoleMiddleware::class, 21 | 'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class, 22 | 'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class, 23 | ]); 24 | // 25 | }) 26 | ->withExceptions(function (Exceptions $exceptions) { 27 | // 28 | })->create(); 29 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /bootstrap/providers.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Environment 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This value determines the "environment" your application is currently 24 | | running in. This may determine how you prefer to configure various 25 | | services the application utilizes. Set this in your ".env" file. 26 | | 27 | */ 28 | 29 | 'env' => env('APP_ENV', 'production'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Debug Mode 34 | |-------------------------------------------------------------------------- 35 | | 36 | | When your application is in debug mode, detailed error messages with 37 | | stack traces will be shown on every error that occurs within your 38 | | application. If disabled, a simple generic error page is shown. 39 | | 40 | */ 41 | 42 | 'debug' => (bool) env('APP_DEBUG', false), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application URL 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This URL is used by the console to properly generate URLs when using 50 | | the Artisan command line tool. You should set this to the root of 51 | | the application so that it's available within Artisan commands. 52 | | 53 | */ 54 | 55 | 'url' => env('APP_URL', 'http://localhost'), 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Application Timezone 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Here you may specify the default timezone for your application, which 63 | | will be used by the PHP date and date-time functions. The timezone 64 | | is set to "UTC" by default as it is suitable for most use cases. 65 | | 66 | */ 67 | 68 | 'timezone' => env('APP_TIMEZONE', 'UTC'), 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Application Locale Configuration 73 | |-------------------------------------------------------------------------- 74 | | 75 | | The application locale determines the default locale that will be used 76 | | by Laravel's translation / localization methods. This option can be 77 | | set to any locale for which you plan to have translation strings. 78 | | 79 | */ 80 | 81 | 'locale' => env('APP_LOCALE', 'en'), 82 | 83 | 'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'), 84 | 85 | 'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'), 86 | 87 | /* 88 | |-------------------------------------------------------------------------- 89 | | Encryption Key 90 | |-------------------------------------------------------------------------- 91 | | 92 | | This key is utilized by Laravel's encryption services and should be set 93 | | to a random, 32 character string to ensure that all encrypted values 94 | | are secure. You should do this prior to deploying the application. 95 | | 96 | */ 97 | 98 | 'cipher' => 'AES-256-CBC', 99 | 100 | 'key' => env('APP_KEY'), 101 | 102 | 'previous_keys' => [ 103 | ...array_filter( 104 | explode(',', env('APP_PREVIOUS_KEYS', '')) 105 | ), 106 | ], 107 | 108 | /* 109 | |-------------------------------------------------------------------------- 110 | | Maintenance Mode Driver 111 | |-------------------------------------------------------------------------- 112 | | 113 | | These configuration options determine the driver used to determine and 114 | | manage Laravel's "maintenance mode" status. The "cache" driver will 115 | | allow maintenance mode to be controlled across multiple machines. 116 | | 117 | | Supported drivers: "file", "cache" 118 | | 119 | */ 120 | 121 | 'maintenance' => [ 122 | 'driver' => env('APP_MAINTENANCE_DRIVER', 'file'), 123 | 'store' => env('APP_MAINTENANCE_STORE', 'database'), 124 | ], 125 | 126 | ]; 127 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => env('AUTH_GUARD', 'web'), 18 | 'passwords' => env('AUTH_PASSWORD_BROKER', 'users'), 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | which utilizes session storage plus the Eloquent user provider. 29 | | 30 | | All authentication guards have a user provider, which defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | system used by the application. Typically, Eloquent is utilized. 33 | | 34 | | Supported: "session" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | ], 44 | 45 | /* 46 | |-------------------------------------------------------------------------- 47 | | User Providers 48 | |-------------------------------------------------------------------------- 49 | | 50 | | All authentication guards have a user provider, which defines how the 51 | | users are actually retrieved out of your database or other storage 52 | | system used by the application. Typically, Eloquent is utilized. 53 | | 54 | | If you have multiple user tables or models you may configure multiple 55 | | providers to represent the model / table. These providers may then 56 | | be assigned to any extra authentication guards you have defined. 57 | | 58 | | Supported: "database", "eloquent" 59 | | 60 | */ 61 | 62 | 'providers' => [ 63 | 'users' => [ 64 | 'driver' => 'eloquent', 65 | 'model' => env('AUTH_MODEL', App\Models\User::class), 66 | ], 67 | 68 | // 'users' => [ 69 | // 'driver' => 'database', 70 | // 'table' => 'users', 71 | // ], 72 | ], 73 | 74 | /* 75 | |-------------------------------------------------------------------------- 76 | | Resetting Passwords 77 | |-------------------------------------------------------------------------- 78 | | 79 | | These configuration options specify the behavior of Laravel's password 80 | | reset functionality, including the table utilized for token storage 81 | | and the user provider that is invoked to actually retrieve users. 82 | | 83 | | The expiry time is the number of minutes that each reset token will be 84 | | considered valid. This security feature keeps tokens short-lived so 85 | | they have less time to be guessed. You may change this as needed. 86 | | 87 | | The throttle setting is the number of seconds a user must wait before 88 | | generating more password reset tokens. This prevents the user from 89 | | quickly generating a very large amount of password reset tokens. 90 | | 91 | */ 92 | 93 | 'passwords' => [ 94 | 'users' => [ 95 | 'provider' => 'users', 96 | 'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'), 97 | 'expire' => 60, 98 | 'throttle' => 60, 99 | ], 100 | ], 101 | 102 | /* 103 | |-------------------------------------------------------------------------- 104 | | Password Confirmation Timeout 105 | |-------------------------------------------------------------------------- 106 | | 107 | | Here you may define the amount of seconds before a password confirmation 108 | | window expires and users are asked to re-enter their password via the 109 | | confirmation screen. By default, the timeout lasts for three hours. 110 | | 111 | */ 112 | 113 | 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800), 114 | 115 | ]; 116 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_STORE', 'database'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | | Supported drivers: "array", "database", "file", "memcached", 30 | | "redis", "dynamodb", "octane", "null" 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'array' => [ 37 | 'driver' => 'array', 38 | 'serialize' => false, 39 | ], 40 | 41 | 'database' => [ 42 | 'driver' => 'database', 43 | 'connection' => env('DB_CACHE_CONNECTION'), 44 | 'table' => env('DB_CACHE_TABLE', 'cache'), 45 | 'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'), 46 | 'lock_table' => env('DB_CACHE_LOCK_TABLE'), 47 | ], 48 | 49 | 'file' => [ 50 | 'driver' => 'file', 51 | 'path' => storage_path('framework/cache/data'), 52 | 'lock_path' => storage_path('framework/cache/data'), 53 | ], 54 | 55 | 'memcached' => [ 56 | 'driver' => 'memcached', 57 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 58 | 'sasl' => [ 59 | env('MEMCACHED_USERNAME'), 60 | env('MEMCACHED_PASSWORD'), 61 | ], 62 | 'options' => [ 63 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 64 | ], 65 | 'servers' => [ 66 | [ 67 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 68 | 'port' => env('MEMCACHED_PORT', 11211), 69 | 'weight' => 100, 70 | ], 71 | ], 72 | ], 73 | 74 | 'redis' => [ 75 | 'driver' => 'redis', 76 | 'connection' => env('REDIS_CACHE_CONNECTION', 'cache'), 77 | 'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'), 78 | ], 79 | 80 | 'dynamodb' => [ 81 | 'driver' => 'dynamodb', 82 | 'key' => env('AWS_ACCESS_KEY_ID'), 83 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 84 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 85 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 86 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 87 | ], 88 | 89 | 'octane' => [ 90 | 'driver' => 'octane', 91 | ], 92 | 93 | ], 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Cache Key Prefix 98 | |-------------------------------------------------------------------------- 99 | | 100 | | When utilizing the APC, database, memcached, Redis, and DynamoDB cache 101 | | stores, there might be other applications using the same cache. For 102 | | that reason, you may prefix every cache key to avoid collisions. 103 | | 104 | */ 105 | 106 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'), 107 | 108 | ]; 109 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | env('DB_CONNECTION', 'sqlite'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Database Connections 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Below are all of the database connections defined for your application. 27 | | An example configuration is provided for each database system which 28 | | is supported by Laravel. You're free to add / remove connections. 29 | | 30 | */ 31 | 32 | 'connections' => [ 33 | 34 | 'sqlite' => [ 35 | 'driver' => 'sqlite', 36 | 'url' => env('DB_URL'), 37 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 38 | 'prefix' => '', 39 | 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 40 | 'busy_timeout' => null, 41 | 'journal_mode' => null, 42 | 'synchronous' => null, 43 | ], 44 | 45 | 'mysql' => [ 46 | 'driver' => 'mysql', 47 | 'url' => env('DB_URL'), 48 | 'host' => env('DB_HOST', '127.0.0.1'), 49 | 'port' => env('DB_PORT', '3306'), 50 | 'database' => env('DB_DATABASE', 'laravel'), 51 | 'username' => env('DB_USERNAME', 'root'), 52 | 'password' => env('DB_PASSWORD', ''), 53 | 'unix_socket' => env('DB_SOCKET', ''), 54 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 55 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 56 | 'prefix' => '', 57 | 'prefix_indexes' => true, 58 | 'strict' => true, 59 | 'engine' => null, 60 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 61 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 62 | ]) : [], 63 | ], 64 | 65 | 'mariadb' => [ 66 | 'driver' => 'mariadb', 67 | 'url' => env('DB_URL'), 68 | 'host' => env('DB_HOST', '127.0.0.1'), 69 | 'port' => env('DB_PORT', '3306'), 70 | 'database' => env('DB_DATABASE', 'laravel'), 71 | 'username' => env('DB_USERNAME', 'root'), 72 | 'password' => env('DB_PASSWORD', ''), 73 | 'unix_socket' => env('DB_SOCKET', ''), 74 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 75 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 76 | 'prefix' => '', 77 | 'prefix_indexes' => true, 78 | 'strict' => true, 79 | 'engine' => null, 80 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 81 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 82 | ]) : [], 83 | ], 84 | 85 | 'pgsql' => [ 86 | 'driver' => 'pgsql', 87 | 'url' => env('DB_URL'), 88 | 'host' => env('DB_HOST', '127.0.0.1'), 89 | 'port' => env('DB_PORT', '5432'), 90 | 'database' => env('DB_DATABASE', 'laravel'), 91 | 'username' => env('DB_USERNAME', 'root'), 92 | 'password' => env('DB_PASSWORD', ''), 93 | 'charset' => env('DB_CHARSET', 'utf8'), 94 | 'prefix' => '', 95 | 'prefix_indexes' => true, 96 | 'search_path' => 'public', 97 | 'sslmode' => 'prefer', 98 | ], 99 | 100 | 'sqlsrv' => [ 101 | 'driver' => 'sqlsrv', 102 | 'url' => env('DB_URL'), 103 | 'host' => env('DB_HOST', 'localhost'), 104 | 'port' => env('DB_PORT', '1433'), 105 | 'database' => env('DB_DATABASE', 'laravel'), 106 | 'username' => env('DB_USERNAME', 'root'), 107 | 'password' => env('DB_PASSWORD', ''), 108 | 'charset' => env('DB_CHARSET', 'utf8'), 109 | 'prefix' => '', 110 | 'prefix_indexes' => true, 111 | // 'encrypt' => env('DB_ENCRYPT', 'yes'), 112 | // 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'), 113 | ], 114 | 115 | ], 116 | 117 | /* 118 | |-------------------------------------------------------------------------- 119 | | Migration Repository Table 120 | |-------------------------------------------------------------------------- 121 | | 122 | | This table keeps track of all the migrations that have already run for 123 | | your application. Using this information, we can determine which of 124 | | the migrations on disk haven't actually been run on the database. 125 | | 126 | */ 127 | 128 | 'migrations' => [ 129 | 'table' => 'migrations', 130 | 'update_date_on_publish' => true, 131 | ], 132 | 133 | /* 134 | |-------------------------------------------------------------------------- 135 | | Redis Databases 136 | |-------------------------------------------------------------------------- 137 | | 138 | | Redis is an open source, fast, and advanced key-value store that also 139 | | provides a richer body of commands than a typical key-value system 140 | | such as Memcached. You may define your connection settings here. 141 | | 142 | */ 143 | 144 | 'redis' => [ 145 | 146 | 'client' => env('REDIS_CLIENT', 'phpredis'), 147 | 148 | 'options' => [ 149 | 'cluster' => env('REDIS_CLUSTER', 'redis'), 150 | 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), 151 | ], 152 | 153 | 'default' => [ 154 | 'url' => env('REDIS_URL'), 155 | 'host' => env('REDIS_HOST', '127.0.0.1'), 156 | 'username' => env('REDIS_USERNAME'), 157 | 'password' => env('REDIS_PASSWORD'), 158 | 'port' => env('REDIS_PORT', '6379'), 159 | 'database' => env('REDIS_DB', '0'), 160 | ], 161 | 162 | 'cache' => [ 163 | 'url' => env('REDIS_URL'), 164 | 'host' => env('REDIS_HOST', '127.0.0.1'), 165 | 'username' => env('REDIS_USERNAME'), 166 | 'password' => env('REDIS_PASSWORD'), 167 | 'port' => env('REDIS_PORT', '6379'), 168 | 'database' => env('REDIS_CACHE_DB', '1'), 169 | ], 170 | 171 | ], 172 | 173 | ]; 174 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DISK', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Filesystem Disks 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Below you may configure as many filesystem disks as necessary, and you 24 | | may even configure multiple disks for the same driver. Examples for 25 | | most supported storage drivers are configured here for reference. 26 | | 27 | | Supported drivers: "local", "ftp", "sftp", "s3" 28 | | 29 | */ 30 | 31 | 'disks' => [ 32 | 33 | 'local' => [ 34 | 'driver' => 'local', 35 | 'root' => storage_path('app/private'), 36 | 'serve' => true, 37 | 'throw' => false, 38 | ], 39 | 40 | 'public' => [ 41 | 'driver' => 'local', 42 | 'root' => storage_path('app/public'), 43 | 'url' => env('APP_URL').'/storage', 44 | 'visibility' => 'public', 45 | 'throw' => false, 46 | ], 47 | 48 | 's3' => [ 49 | 'driver' => 's3', 50 | 'key' => env('AWS_ACCESS_KEY_ID'), 51 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 52 | 'region' => env('AWS_DEFAULT_REGION'), 53 | 'bucket' => env('AWS_BUCKET'), 54 | 'url' => env('AWS_URL'), 55 | 'endpoint' => env('AWS_ENDPOINT'), 56 | 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), 57 | 'throw' => false, 58 | ], 59 | 60 | ], 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Symbolic Links 65 | |-------------------------------------------------------------------------- 66 | | 67 | | Here you may configure the symbolic links that will be created when the 68 | | `storage:link` Artisan command is executed. The array keys should be 69 | | the locations of the links and the values should be their targets. 70 | | 71 | */ 72 | 73 | 'links' => [ 74 | public_path('storage') => storage_path('app/public'), 75 | ], 76 | 77 | ]; 78 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Deprecations Log Channel 26 | |-------------------------------------------------------------------------- 27 | | 28 | | This option controls the log channel that should be used to log warnings 29 | | regarding deprecated PHP and library features. This allows you to get 30 | | your application ready for upcoming major versions of dependencies. 31 | | 32 | */ 33 | 34 | 'deprecations' => [ 35 | 'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'), 36 | 'trace' => env('LOG_DEPRECATIONS_TRACE', false), 37 | ], 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Log Channels 42 | |-------------------------------------------------------------------------- 43 | | 44 | | Here you may configure the log channels for your application. Laravel 45 | | utilizes the Monolog PHP logging library, which includes a variety 46 | | of powerful log handlers and formatters that you're free to use. 47 | | 48 | | Available drivers: "single", "daily", "slack", "syslog", 49 | | "errorlog", "monolog", "custom", "stack" 50 | | 51 | */ 52 | 53 | 'channels' => [ 54 | 55 | 'stack' => [ 56 | 'driver' => 'stack', 57 | 'channels' => explode(',', env('LOG_STACK', 'single')), 58 | 'ignore_exceptions' => false, 59 | ], 60 | 61 | 'single' => [ 62 | 'driver' => 'single', 63 | 'path' => storage_path('logs/laravel.log'), 64 | 'level' => env('LOG_LEVEL', 'debug'), 65 | 'replace_placeholders' => true, 66 | ], 67 | 68 | 'daily' => [ 69 | 'driver' => 'daily', 70 | 'path' => storage_path('logs/laravel.log'), 71 | 'level' => env('LOG_LEVEL', 'debug'), 72 | 'days' => env('LOG_DAILY_DAYS', 14), 73 | 'replace_placeholders' => true, 74 | ], 75 | 76 | 'slack' => [ 77 | 'driver' => 'slack', 78 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 79 | 'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'), 80 | 'emoji' => env('LOG_SLACK_EMOJI', ':boom:'), 81 | 'level' => env('LOG_LEVEL', 'critical'), 82 | 'replace_placeholders' => true, 83 | ], 84 | 85 | 'papertrail' => [ 86 | 'driver' => 'monolog', 87 | 'level' => env('LOG_LEVEL', 'debug'), 88 | 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), 89 | 'handler_with' => [ 90 | 'host' => env('PAPERTRAIL_URL'), 91 | 'port' => env('PAPERTRAIL_PORT'), 92 | 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), 93 | ], 94 | 'processors' => [PsrLogMessageProcessor::class], 95 | ], 96 | 97 | 'stderr' => [ 98 | 'driver' => 'monolog', 99 | 'level' => env('LOG_LEVEL', 'debug'), 100 | 'handler' => StreamHandler::class, 101 | 'formatter' => env('LOG_STDERR_FORMATTER'), 102 | 'with' => [ 103 | 'stream' => 'php://stderr', 104 | ], 105 | 'processors' => [PsrLogMessageProcessor::class], 106 | ], 107 | 108 | 'syslog' => [ 109 | 'driver' => 'syslog', 110 | 'level' => env('LOG_LEVEL', 'debug'), 111 | 'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER), 112 | 'replace_placeholders' => true, 113 | ], 114 | 115 | 'errorlog' => [ 116 | 'driver' => 'errorlog', 117 | 'level' => env('LOG_LEVEL', 'debug'), 118 | 'replace_placeholders' => true, 119 | ], 120 | 121 | 'null' => [ 122 | 'driver' => 'monolog', 123 | 'handler' => NullHandler::class, 124 | ], 125 | 126 | 'emergency' => [ 127 | 'path' => storage_path('logs/laravel.log'), 128 | ], 129 | 130 | ], 131 | 132 | ]; 133 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_MAILER', 'log'), 18 | 19 | /* 20 | |-------------------------------------------------------------------------- 21 | | Mailer Configurations 22 | |-------------------------------------------------------------------------- 23 | | 24 | | Here you may configure all of the mailers used by your application plus 25 | | their respective settings. Several examples have been configured for 26 | | you and you are free to add your own as your application requires. 27 | | 28 | | Laravel supports a variety of mail "transport" drivers that can be used 29 | | when delivering an email. You may specify which one you're using for 30 | | your mailers below. You may also add additional mailers if needed. 31 | | 32 | | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2", 33 | | "postmark", "resend", "log", "array", 34 | | "failover", "roundrobin" 35 | | 36 | */ 37 | 38 | 'mailers' => [ 39 | 40 | 'smtp' => [ 41 | 'transport' => 'smtp', 42 | 'url' => env('MAIL_URL'), 43 | 'host' => env('MAIL_HOST', '127.0.0.1'), 44 | 'port' => env('MAIL_PORT', 2525), 45 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 46 | 'username' => env('MAIL_USERNAME'), 47 | 'password' => env('MAIL_PASSWORD'), 48 | 'timeout' => null, 49 | 'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url(env('APP_URL', 'http://localhost'), PHP_URL_HOST)), 50 | ], 51 | 52 | 'ses' => [ 53 | 'transport' => 'ses', 54 | ], 55 | 56 | 'postmark' => [ 57 | 'transport' => 'postmark', 58 | // 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'), 59 | // 'client' => [ 60 | // 'timeout' => 5, 61 | // ], 62 | ], 63 | 64 | 'resend' => [ 65 | 'transport' => 'resend', 66 | ], 67 | 68 | 'sendmail' => [ 69 | 'transport' => 'sendmail', 70 | 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'), 71 | ], 72 | 73 | 'log' => [ 74 | 'transport' => 'log', 75 | 'channel' => env('MAIL_LOG_CHANNEL'), 76 | ], 77 | 78 | 'array' => [ 79 | 'transport' => 'array', 80 | ], 81 | 82 | 'failover' => [ 83 | 'transport' => 'failover', 84 | 'mailers' => [ 85 | 'smtp', 86 | 'log', 87 | ], 88 | ], 89 | 90 | 'roundrobin' => [ 91 | 'transport' => 'roundrobin', 92 | 'mailers' => [ 93 | 'ses', 94 | 'postmark', 95 | ], 96 | ], 97 | 98 | ], 99 | 100 | /* 101 | |-------------------------------------------------------------------------- 102 | | Global "From" Address 103 | |-------------------------------------------------------------------------- 104 | | 105 | | You may wish for all emails sent by your application to be sent from 106 | | the same address. Here you may specify a name and address that is 107 | | used globally for all emails that are sent by your application. 108 | | 109 | */ 110 | 111 | 'from' => [ 112 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 113 | 'name' => env('MAIL_FROM_NAME', 'Example'), 114 | ], 115 | 116 | ]; 117 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'database'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection options for every queue backend 24 | | used by your application. An example configuration is provided for 25 | | each backend supported by Laravel. You're also free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'connection' => env('DB_QUEUE_CONNECTION'), 40 | 'table' => env('DB_QUEUE_TABLE', 'jobs'), 41 | 'queue' => env('DB_QUEUE', 'default'), 42 | 'retry_after' => (int) env('DB_QUEUE_RETRY_AFTER', 90), 43 | 'after_commit' => false, 44 | ], 45 | 46 | 'beanstalkd' => [ 47 | 'driver' => 'beanstalkd', 48 | 'host' => env('BEANSTALKD_QUEUE_HOST', 'localhost'), 49 | 'queue' => env('BEANSTALKD_QUEUE', 'default'), 50 | 'retry_after' => (int) env('BEANSTALKD_QUEUE_RETRY_AFTER', 90), 51 | 'block_for' => 0, 52 | 'after_commit' => false, 53 | ], 54 | 55 | 'sqs' => [ 56 | 'driver' => 'sqs', 57 | 'key' => env('AWS_ACCESS_KEY_ID'), 58 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 59 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 60 | 'queue' => env('SQS_QUEUE', 'default'), 61 | 'suffix' => env('SQS_SUFFIX'), 62 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 63 | 'after_commit' => false, 64 | ], 65 | 66 | 'redis' => [ 67 | 'driver' => 'redis', 68 | 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'), 69 | 'queue' => env('REDIS_QUEUE', 'default'), 70 | 'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90), 71 | 'block_for' => null, 72 | 'after_commit' => false, 73 | ], 74 | 75 | ], 76 | 77 | /* 78 | |-------------------------------------------------------------------------- 79 | | Job Batching 80 | |-------------------------------------------------------------------------- 81 | | 82 | | The following options configure the database and table that store job 83 | | batching information. These options can be updated to any database 84 | | connection and table which has been defined by your application. 85 | | 86 | */ 87 | 88 | 'batching' => [ 89 | 'database' => env('DB_CONNECTION', 'sqlite'), 90 | 'table' => 'job_batches', 91 | ], 92 | 93 | /* 94 | |-------------------------------------------------------------------------- 95 | | Failed Queue Jobs 96 | |-------------------------------------------------------------------------- 97 | | 98 | | These options configure the behavior of failed queue job logging so you 99 | | can control how and where failed jobs are stored. Laravel ships with 100 | | support for storing failed jobs in a simple file or in a database. 101 | | 102 | | Supported drivers: "database-uuids", "dynamodb", "file", "null" 103 | | 104 | */ 105 | 106 | 'failed' => [ 107 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), 108 | 'database' => env('DB_CONNECTION', 'sqlite'), 109 | 'table' => 'failed_jobs', 110 | ], 111 | 112 | ]; 113 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'token' => env('POSTMARK_TOKEN'), 19 | ], 20 | 21 | 'ses' => [ 22 | 'key' => env('AWS_ACCESS_KEY_ID'), 23 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 24 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 25 | ], 26 | 27 | 'resend' => [ 28 | 'key' => env('RESEND_KEY'), 29 | ], 30 | 31 | 'slack' => [ 32 | 'notifications' => [ 33 | 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'), 34 | 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'), 35 | ], 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite* 2 | -------------------------------------------------------------------------------- /database/factories/FeatureFactory.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class FeatureFactory extends Factory 12 | { 13 | /** 14 | * Define the model's default state. 15 | * 16 | * @return array 17 | */ 18 | public function definition(): array 19 | { 20 | return [ 21 | 'name' => fake()->text(), 22 | 'description' => fake()->text(2000), 23 | 'user_id' => User::where('email', 'admin@example.com')->first()->id, 24 | ]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class UserFactory extends Factory 13 | { 14 | /** 15 | * The current password being used by the factory. 16 | */ 17 | protected static ?string $password; 18 | 19 | /** 20 | * Define the model's default state. 21 | * 22 | * @return array 23 | */ 24 | public function definition(): array 25 | { 26 | return [ 27 | 'name' => fake()->name(), 28 | 'email' => fake()->unique()->safeEmail(), 29 | 'email_verified_at' => now(), 30 | 'password' => static::$password ??= Hash::make('password'), 31 | 'remember_token' => Str::random(10), 32 | ]; 33 | } 34 | 35 | /** 36 | * Indicate that the model's email address should be unverified. 37 | */ 38 | public function unverified(): static 39 | { 40 | return $this->state(fn (array $attributes) => [ 41 | 'email_verified_at' => null, 42 | ]); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('name'); 17 | $table->string('email')->unique(); 18 | $table->timestamp('email_verified_at')->nullable(); 19 | $table->string('password'); 20 | $table->rememberToken(); 21 | $table->timestamps(); 22 | }); 23 | 24 | Schema::create('password_reset_tokens', function (Blueprint $table) { 25 | $table->string('email')->primary(); 26 | $table->string('token'); 27 | $table->timestamp('created_at')->nullable(); 28 | }); 29 | 30 | Schema::create('sessions', function (Blueprint $table) { 31 | $table->string('id')->primary(); 32 | $table->foreignId('user_id')->nullable()->index(); 33 | $table->string('ip_address', 45)->nullable(); 34 | $table->text('user_agent')->nullable(); 35 | $table->longText('payload'); 36 | $table->integer('last_activity')->index(); 37 | }); 38 | } 39 | 40 | /** 41 | * Reverse the migrations. 42 | */ 43 | public function down(): void 44 | { 45 | Schema::dropIfExists('users'); 46 | Schema::dropIfExists('password_reset_tokens'); 47 | Schema::dropIfExists('sessions'); 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /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/2024_11_01_163644_create_permission_tables.php: -------------------------------------------------------------------------------- 1 | engine('InnoDB'); 29 | $table->bigIncrements('id'); // permission id 30 | $table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format) 31 | $table->string('guard_name'); // For MyISAM use string('guard_name', 25); 32 | $table->timestamps(); 33 | 34 | $table->unique(['name', 'guard_name']); 35 | }); 36 | 37 | Schema::create($tableNames['roles'], function (Blueprint $table) use ($teams, $columnNames) { 38 | //$table->engine('InnoDB'); 39 | $table->bigIncrements('id'); // role id 40 | if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing 41 | $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable(); 42 | $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); 43 | } 44 | $table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format) 45 | $table->string('guard_name'); // For MyISAM use string('guard_name', 25); 46 | $table->timestamps(); 47 | if ($teams || config('permission.testing')) { 48 | $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); 49 | } else { 50 | $table->unique(['name', 'guard_name']); 51 | } 52 | }); 53 | 54 | Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) { 55 | $table->unsignedBigInteger($pivotPermission); 56 | 57 | $table->string('model_type'); 58 | $table->unsignedBigInteger($columnNames['model_morph_key']); 59 | $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); 60 | 61 | $table->foreign($pivotPermission) 62 | ->references('id') // permission id 63 | ->on($tableNames['permissions']) 64 | ->onDelete('cascade'); 65 | if ($teams) { 66 | $table->unsignedBigInteger($columnNames['team_foreign_key']); 67 | $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); 68 | 69 | $table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'], 70 | 'model_has_permissions_permission_model_type_primary'); 71 | } else { 72 | $table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'], 73 | 'model_has_permissions_permission_model_type_primary'); 74 | } 75 | 76 | }); 77 | 78 | Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) { 79 | $table->unsignedBigInteger($pivotRole); 80 | 81 | $table->string('model_type'); 82 | $table->unsignedBigInteger($columnNames['model_morph_key']); 83 | $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); 84 | 85 | $table->foreign($pivotRole) 86 | ->references('id') // role id 87 | ->on($tableNames['roles']) 88 | ->onDelete('cascade'); 89 | if ($teams) { 90 | $table->unsignedBigInteger($columnNames['team_foreign_key']); 91 | $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); 92 | 93 | $table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'], 94 | 'model_has_roles_role_model_type_primary'); 95 | } else { 96 | $table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'], 97 | 'model_has_roles_role_model_type_primary'); 98 | } 99 | }); 100 | 101 | Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) { 102 | $table->unsignedBigInteger($pivotPermission); 103 | $table->unsignedBigInteger($pivotRole); 104 | 105 | $table->foreign($pivotPermission) 106 | ->references('id') // permission id 107 | ->on($tableNames['permissions']) 108 | ->onDelete('cascade'); 109 | 110 | $table->foreign($pivotRole) 111 | ->references('id') // role id 112 | ->on($tableNames['roles']) 113 | ->onDelete('cascade'); 114 | 115 | $table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary'); 116 | }); 117 | 118 | app('cache') 119 | ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) 120 | ->forget(config('permission.cache.key')); 121 | } 122 | 123 | /** 124 | * Reverse the migrations. 125 | */ 126 | public function down(): void 127 | { 128 | $tableNames = config('permission.table_names'); 129 | 130 | if (empty($tableNames)) { 131 | throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); 132 | } 133 | 134 | Schema::drop($tableNames['role_has_permissions']); 135 | Schema::drop($tableNames['model_has_roles']); 136 | Schema::drop($tableNames['model_has_permissions']); 137 | Schema::drop($tableNames['roles']); 138 | Schema::drop($tableNames['permissions']); 139 | } 140 | }; 141 | -------------------------------------------------------------------------------- /database/migrations/2024_11_01_170947_create_features_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('name'); 17 | $table->longText('description')->nullable(); 18 | $table->foreignIdFor(\App\Models\User::class); 19 | $table->timestamps(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | */ 26 | public function down(): void 27 | { 28 | Schema::dropIfExists('features'); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /database/migrations/2024_11_01_171010_create_upvotes_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->foreignId('feature_id') 17 | ->constrained('features') 18 | ->cascadeOnDelete(); 19 | $table->foreignId('user_id') 20 | ->constrained('users') 21 | ->cascadeOnDelete(); 22 | $table->boolean('upvote'); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | */ 29 | public function down(): void 30 | { 31 | Schema::dropIfExists('upvotes'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /database/migrations/2024_11_01_171020_create_comments_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('comment', 2000); 17 | $table->foreignId('feature_id') 18 | ->constrained('features') 19 | ->cascadeOnDelete(); 20 | $table->foreignId('user_id') 21 | ->constrained('users') 22 | ->cascadeOnDelete(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | */ 30 | public function down(): void 31 | { 32 | Schema::dropIfExists('comments'); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /database/seeders/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | RolesEnum::User->value]); 22 | $commenterRole = Role::create(['name' => RolesEnum::Commenter->value]); 23 | $adminRole = Role::create(['name' => RolesEnum::Admin->value]); 24 | 25 | $manageFeaturesPermission = Permission::create([ 26 | 'name' => PermissionsEnum::ManageFeatures->value, 27 | ]); 28 | $manageCommentsPermission = Permission::create([ 29 | 'name' => PermissionsEnum::ManageComments->value, 30 | ]); 31 | $manageUsersPermission = Permission::create([ 32 | 'name' => PermissionsEnum::ManageUsers->value, 33 | ]); 34 | $upvoteDownvotePermission = Permission::create([ 35 | 'name' => PermissionsEnum::UpvoteDownvote->value, 36 | ]); 37 | 38 | $userRole->syncPermissions([$upvoteDownvotePermission]); 39 | $commenterRole->syncPermissions([$upvoteDownvotePermission, $manageCommentsPermission]); 40 | $adminRole->syncPermissions([ 41 | $upvoteDownvotePermission, 42 | $manageUsersPermission, 43 | $manageCommentsPermission, 44 | $manageFeaturesPermission, 45 | ]); 46 | 47 | User::factory()->create([ 48 | 'name' => 'User User', 49 | 'email' => 'user@example.com', 50 | ])->assignRole(RolesEnum::User); 51 | 52 | User::factory()->create([ 53 | 'name' => 'Commenter User', 54 | 'email' => 'commenter@example.com', 55 | ])->assignRole(RolesEnum::Commenter); 56 | 57 | User::factory()->create([ 58 | 'name' => 'Admin User', 59 | 'email' => 'admin@example.com', 60 | ])->assignRole(RolesEnum::Admin); 61 | 62 | Feature::factory(100)->create(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "type": "module", 4 | "scripts": { 5 | "build": "tsc && vite build && vite build --ssr", 6 | "dev": "vite" 7 | }, 8 | "devDependencies": { 9 | "@headlessui/react": "^2.0.0", 10 | "@inertiajs/react": "^2.0.0-beta.2", 11 | "@tailwindcss/forms": "^0.5.3", 12 | "@types/node": "^18.13.0", 13 | "@types/react": "^18.0.28", 14 | "@types/react-dom": "^18.0.10", 15 | "@vitejs/plugin-react": "^4.2.0", 16 | "autoprefixer": "^10.4.12", 17 | "axios": "^1.7.4", 18 | "concurrently": "^9.0.1", 19 | "laravel-vite-plugin": "^1.0", 20 | "postcss": "^8.4.31", 21 | "react": "^18.2.0", 22 | "react-dom": "^18.2.0", 23 | "tailwindcss": "^3.2.1", 24 | "typescript": "^5.0.2", 25 | "vite": "^5.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /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 | 33 | 34 | -------------------------------------------------------------------------------- /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/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecodeholic/laravel-react-inertia2-ssr/393143fd746823b1187f6e7b6c2b6cb9cb849b65/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | handleRequest(Request::capture()); 18 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /resources/css/app.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /resources/js/Components/ApplicationLogo.tsx: -------------------------------------------------------------------------------- 1 | import { SVGAttributes } from 'react'; 2 | 3 | export default function ApplicationLogo(props: SVGAttributes) { 4 | return ( 5 | 10 | 11 | 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /resources/js/Components/Checkbox.tsx: -------------------------------------------------------------------------------- 1 | import { InputHTMLAttributes } from 'react'; 2 | 3 | export default function Checkbox({ 4 | className = '', 5 | ...props 6 | }: InputHTMLAttributes) { 7 | return ( 8 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /resources/js/Components/CommentItem.tsx: -------------------------------------------------------------------------------- 1 | import {Comment} from "@/types"; 2 | import {useForm, usePage} from "@inertiajs/react"; 3 | import {can} from "@/helpers"; 4 | 5 | export default function CommentItem({comment}: { comment: Comment }) { 6 | const user = usePage().props.auth.user; 7 | const form = useForm(); 8 | 9 | const deleteComment = () => { 10 | form.delete(route('comment.destroy', comment.id), { 11 | preserveScroll: true, 12 | preserveState: true 13 | }) 14 | } 15 | 16 | return ( 17 |
18 |
19 | 21 | 23 | 24 |
25 |
26 |

27 | {comment.user.name} 28 | {comment.created_at} 29 |

30 |
{comment.comment}
31 |
32 | {can(user, 'manage_comments') && comment.user.id == user.id &&
33 | 41 |
} 42 |
43 | ); 44 | } 45 | -------------------------------------------------------------------------------- /resources/js/Components/DangerButton.tsx: -------------------------------------------------------------------------------- 1 | import { ButtonHTMLAttributes } from 'react'; 2 | 3 | export default function DangerButton({ 4 | className = '', 5 | disabled, 6 | children, 7 | ...props 8 | }: ButtonHTMLAttributes) { 9 | return ( 10 | 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /resources/js/Components/Dropdown.tsx: -------------------------------------------------------------------------------- 1 | import {Transition} from '@headlessui/react'; 2 | import {InertiaLinkProps, Link} from '@inertiajs/react'; 3 | import { 4 | createContext, 5 | Dispatch, 6 | PropsWithChildren, 7 | SetStateAction, 8 | useContext, 9 | useState, 10 | } from 'react'; 11 | 12 | const DropDownContext = createContext<{ 13 | open: boolean; 14 | setOpen: Dispatch>; 15 | toggleOpen: () => void; 16 | }>({ 17 | open: false, 18 | setOpen: () => { 19 | }, 20 | toggleOpen: () => { 21 | }, 22 | }); 23 | 24 | const Dropdown = ({children}: PropsWithChildren) => { 25 | const [open, setOpen] = useState(false); 26 | 27 | const toggleOpen = () => { 28 | setOpen((previousState) => !previousState); 29 | }; 30 | 31 | return ( 32 | 33 |
{children}
34 |
35 | ); 36 | }; 37 | 38 | const Trigger = ({children}: PropsWithChildren) => { 39 | const {open, setOpen, toggleOpen} = useContext(DropDownContext); 40 | 41 | return ( 42 | <> 43 |
{children}
44 | 45 | {open && ( 46 |
setOpen(false)} 49 | >
50 | )} 51 | 52 | ); 53 | }; 54 | 55 | const Content = ({ 56 | align = 'right', 57 | width = '48', 58 | contentClasses = 'py-1 bg-white dark:bg-gray-700', 59 | children, 60 | }: PropsWithChildren<{ 61 | align?: 'left' | 'right'; 62 | width?: '48'; 63 | contentClasses?: string; 64 | }>) => { 65 | const {open, setOpen} = useContext(DropDownContext); 66 | 67 | let alignmentClasses = 'origin-top'; 68 | 69 | if (align === 'left') { 70 | alignmentClasses = 'ltr:origin-top-left rtl:origin-top-right start-0'; 71 | } else if (align === 'right') { 72 | alignmentClasses = 'ltr:origin-top-right rtl:origin-top-left end-0'; 73 | } 74 | 75 | let widthClasses = ''; 76 | 77 | if (width === '48') { 78 | widthClasses = 'w-48'; 79 | } 80 | 81 | return ( 82 | <> 83 | 92 |
setOpen(false)} 95 | > 96 |
102 | {children} 103 |
104 |
105 |
106 | 107 | ); 108 | }; 109 | 110 | const DropdownLink = ({ 111 | prefetch, 112 | className = '', 113 | children, 114 | ...props 115 | }: InertiaLinkProps) => { 116 | return ( 117 | 125 | {children} 126 | 127 | ); 128 | }; 129 | 130 | Dropdown.Trigger = Trigger; 131 | Dropdown.Content = Content; 132 | Dropdown.Link = DropdownLink; 133 | 134 | export default Dropdown; 135 | -------------------------------------------------------------------------------- /resources/js/Components/FeatureActionsDropdown.tsx: -------------------------------------------------------------------------------- 1 | import Dropdown from "@/Components/Dropdown"; 2 | import {Feature} from "@/types"; 3 | import {can} from "@/helpers"; 4 | import {usePage} from "@inertiajs/react"; 5 | 6 | export default function FeatureActionsDropdown({feature}: {feature: Feature}) { 7 | const user = usePage().props.auth.user; 8 | 9 | if (!can(user, 'manage_features')) { 10 | return; 11 | } 12 | 13 | return ( 14 | 15 | 16 | 17 | 27 | 28 | 29 | 30 | 31 | 34 | Edit Feature 35 | 36 | 41 | Delete Feature 42 | 43 | 44 | 45 | ) 46 | } 47 | -------------------------------------------------------------------------------- /resources/js/Components/FeatureItem.tsx: -------------------------------------------------------------------------------- 1 | import {Feature} from "@/types"; 2 | import {useState} from "react"; 3 | import {Link} from "@inertiajs/react"; 4 | import FeatureActionsDropdown from "@/Components/FeatureActionsDropdown"; 5 | import FeatureUpvoteDownvote from "@/Components/FeatureUpvoteDownvote"; 6 | 7 | export default function FeatureItem({feature}: {feature: Feature}) { 8 | const [isExpanded, setIsExpanded] = useState(false); 9 | 10 | const toggleReadMore = () => { 11 | setIsExpanded(!isExpanded); 12 | } 13 | 14 | return ( 15 |
16 |
17 | 18 |
19 |

20 | 21 | {feature.name} 22 | 23 |

24 | {(feature.description || '').length > 200 && ( 25 | <> 26 |

{isExpanded ? feature.description : `${(feature.description || '').slice(0, 200)}...`}

27 | 28 | 31 | 32 | )} 33 | {(feature.description || '').length <= 200 && ( 34 |

{feature.description}

35 | )} 36 | 37 |
38 | 40 | Comments 41 | 42 |
43 |
44 |
45 | 46 |
47 |
48 |
49 | ); 50 | } 51 | -------------------------------------------------------------------------------- /resources/js/Components/FeatureUpvoteDownvote.tsx: -------------------------------------------------------------------------------- 1 | import {Feature} from "@/types"; 2 | import {useForm} from "@inertiajs/react"; 3 | 4 | export default function FeatureUpvoteDownvote({feature}: {feature: Feature}) { 5 | const upvoteForm = useForm({ 6 | upvote: true 7 | }); 8 | 9 | const downvoteForm = useForm({ 10 | upvote: false 11 | }); 12 | 13 | const upvoteDownvote = (upvote: boolean) => { 14 | if (feature.user_has_upvoted && upvote || feature.user_has_downvoted && !upvote) { 15 | upvoteForm.delete(route('upvote.destroy', feature.id), { 16 | preserveScroll: true 17 | }); 18 | } else { 19 | let form = null; 20 | if (upvote) { 21 | form = upvoteForm; 22 | } else { 23 | form = downvoteForm; 24 | } 25 | 26 | form.post(route('upvote.store', feature.id), { 27 | preserveScroll: true 28 | }) 29 | } 30 | } 31 | 32 | return ( 33 |
34 | 43 | 45 | {feature.upvote_count} 46 | 47 | 57 |
58 | ) 59 | } 60 | -------------------------------------------------------------------------------- /resources/js/Components/InputError.tsx: -------------------------------------------------------------------------------- 1 | import { HTMLAttributes } from 'react'; 2 | 3 | export default function InputError({ 4 | message, 5 | className = '', 6 | ...props 7 | }: HTMLAttributes & { message?: string }) { 8 | return message ? ( 9 |

13 | {message} 14 |

15 | ) : null; 16 | } 17 | -------------------------------------------------------------------------------- /resources/js/Components/InputLabel.tsx: -------------------------------------------------------------------------------- 1 | import { LabelHTMLAttributes } from 'react'; 2 | 3 | export default function InputLabel({ 4 | value, 5 | className = '', 6 | children, 7 | ...props 8 | }: LabelHTMLAttributes & { value?: string }) { 9 | return ( 10 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /resources/js/Components/Modal.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | Dialog, 3 | DialogPanel, 4 | Transition, 5 | TransitionChild, 6 | } from '@headlessui/react'; 7 | import { PropsWithChildren } from 'react'; 8 | 9 | export default function Modal({ 10 | children, 11 | show = false, 12 | maxWidth = '2xl', 13 | closeable = true, 14 | onClose = () => {}, 15 | }: PropsWithChildren<{ 16 | show: boolean; 17 | maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | '2xl'; 18 | closeable?: boolean; 19 | onClose: CallableFunction; 20 | }>) { 21 | const close = () => { 22 | if (closeable) { 23 | onClose(); 24 | } 25 | }; 26 | 27 | const maxWidthClass = { 28 | sm: 'sm:max-w-sm', 29 | md: 'sm:max-w-md', 30 | lg: 'sm:max-w-lg', 31 | xl: 'sm:max-w-xl', 32 | '2xl': 'sm:max-w-2xl', 33 | }[maxWidth]; 34 | 35 | return ( 36 | 37 | 43 | 51 |
52 | 53 | 54 | 62 | 65 | {children} 66 | 67 | 68 |
69 |
70 | ); 71 | } 72 | -------------------------------------------------------------------------------- /resources/js/Components/NavLink.tsx: -------------------------------------------------------------------------------- 1 | import { InertiaLinkProps, Link } from '@inertiajs/react'; 2 | 3 | export default function NavLink({ 4 | active = false, 5 | className = '', 6 | children, 7 | ...props 8 | }: InertiaLinkProps & { active: boolean }) { 9 | return ( 10 | 20 | {children} 21 | 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /resources/js/Components/NewCommentForm.tsx: -------------------------------------------------------------------------------- 1 | import {Feature} from "@/types"; 2 | import TextAreaInput from "@/Components/TextAreaInput"; 3 | import {useForm, usePage} from "@inertiajs/react"; 4 | import {FormEventHandler} from "react"; 5 | import PrimaryButton from "@/Components/PrimaryButton"; 6 | import {can} from "@/helpers"; 7 | 8 | export default function NewCommentForm({feature}: { feature: Feature }) { 9 | const user = usePage().props.auth.user; 10 | 11 | const { 12 | data, 13 | setData, 14 | post, 15 | processing 16 | } = useForm({ 17 | comment: '' 18 | }) 19 | 20 | const createComment: FormEventHandler = (ev) => { 21 | ev.preventDefault(); 22 | 23 | post(route('comment.store', feature.id), { 24 | preserveScroll: true, 25 | preserveState: true, 26 | onSuccess: () => setData('comment', '') 27 | }) 28 | } 29 | 30 | if (!can(user, 'manage_comments')) { 31 | return ( 32 |
33 | You don't have permission to leave comments 34 |
35 | ); 36 | } 37 | 38 | return ( 39 |
40 | setData('comment', e.target.value)} 44 | className="mt-1 block w-full" 45 | placeholder="Your comment" 46 | > 47 | Comment 48 |
49 | ); 50 | } 51 | -------------------------------------------------------------------------------- /resources/js/Components/PrimaryButton.tsx: -------------------------------------------------------------------------------- 1 | import { ButtonHTMLAttributes } from 'react'; 2 | 3 | export default function PrimaryButton({ 4 | className = '', 5 | disabled, 6 | children, 7 | ...props 8 | }: ButtonHTMLAttributes) { 9 | return ( 10 | 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /resources/js/Components/Radio.tsx: -------------------------------------------------------------------------------- 1 | import { InputHTMLAttributes } from 'react'; 2 | 3 | export default function Radio({ 4 | className = '', 5 | ...props 6 | }: InputHTMLAttributes) { 7 | return ( 8 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /resources/js/Components/ResponsiveNavLink.tsx: -------------------------------------------------------------------------------- 1 | import {InertiaLinkProps, Link} from '@inertiajs/react'; 2 | 3 | export default function ResponsiveNavLink({ 4 | prefetch, 5 | active = false, 6 | className = '', 7 | children, 8 | ...props 9 | }: InertiaLinkProps & { active?: boolean }) { 10 | return ( 11 | 20 | {children} 21 | 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /resources/js/Components/SecondaryButton.tsx: -------------------------------------------------------------------------------- 1 | import { ButtonHTMLAttributes } from 'react'; 2 | 3 | export default function SecondaryButton({ 4 | type = 'button', 5 | className = '', 6 | disabled, 7 | children, 8 | ...props 9 | }: ButtonHTMLAttributes) { 10 | return ( 11 | 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /resources/js/Components/TextAreaInput.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | forwardRef, 3 | InputHTMLAttributes, 4 | useImperativeHandle, 5 | useRef, 6 | } from 'react'; 7 | 8 | export default forwardRef(function TextAreaInput( 9 | { 10 | className = '', 11 | rows = 6, 12 | ...props 13 | }: InputHTMLAttributes & { rows: number }, 14 | ref, 15 | ) { 16 | const localRef = useRef(null); 17 | 18 | useImperativeHandle(ref, () => ({ 19 | focus: () => localRef.current?.focus(), 20 | })); 21 | 22 | return ( 23 | 32 | ); 33 | }); 34 | -------------------------------------------------------------------------------- /resources/js/Components/TextInput.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | forwardRef, 3 | InputHTMLAttributes, 4 | useEffect, 5 | useImperativeHandle, 6 | useRef, 7 | } from 'react'; 8 | 9 | export default forwardRef(function TextInput( 10 | { 11 | type = 'text', 12 | className = '', 13 | isFocused = false, 14 | ...props 15 | }: InputHTMLAttributes & { isFocused?: boolean }, 16 | ref, 17 | ) { 18 | const localRef = useRef(null); 19 | 20 | useImperativeHandle(ref, () => ({ 21 | focus: () => localRef.current?.focus(), 22 | })); 23 | 24 | useEffect(() => { 25 | if (isFocused) { 26 | localRef.current?.focus(); 27 | } 28 | }, [isFocused]); 29 | 30 | return ( 31 | 40 | ); 41 | }); 42 | -------------------------------------------------------------------------------- /resources/js/Layouts/GuestLayout.tsx: -------------------------------------------------------------------------------- 1 | import ApplicationLogo from '@/Components/ApplicationLogo'; 2 | import { Link } from '@inertiajs/react'; 3 | import { PropsWithChildren } from 'react'; 4 | 5 | export default function Guest({ children }: PropsWithChildren) { 6 | return ( 7 |
8 |
9 | 10 | 11 | 12 |
13 | 14 |
15 | {children} 16 |
17 |
18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /resources/js/Pages/Auth/ConfirmPassword.tsx: -------------------------------------------------------------------------------- 1 | import InputError from '@/Components/InputError'; 2 | import InputLabel from '@/Components/InputLabel'; 3 | import PrimaryButton from '@/Components/PrimaryButton'; 4 | import TextInput from '@/Components/TextInput'; 5 | import GuestLayout from '@/Layouts/GuestLayout'; 6 | import { Head, useForm } from '@inertiajs/react'; 7 | import { FormEventHandler } from 'react'; 8 | 9 | export default function ConfirmPassword() { 10 | const { data, setData, post, processing, errors, reset } = useForm({ 11 | password: '', 12 | }); 13 | 14 | const submit: FormEventHandler = (e) => { 15 | e.preventDefault(); 16 | 17 | post(route('password.confirm'), { 18 | onFinish: () => reset('password'), 19 | }); 20 | }; 21 | 22 | return ( 23 | 24 | 25 | 26 |
27 | This is a secure area of the application. Please confirm your 28 | password before continuing. 29 |
30 | 31 |
32 |
33 | 34 | 35 | setData('password', e.target.value)} 43 | /> 44 | 45 | 46 |
47 | 48 |
49 | 50 | Confirm 51 | 52 |
53 |
54 |
55 | ); 56 | } 57 | -------------------------------------------------------------------------------- /resources/js/Pages/Auth/ForgotPassword.tsx: -------------------------------------------------------------------------------- 1 | import InputError from '@/Components/InputError'; 2 | import PrimaryButton from '@/Components/PrimaryButton'; 3 | import TextInput from '@/Components/TextInput'; 4 | import GuestLayout from '@/Layouts/GuestLayout'; 5 | import { Head, useForm } from '@inertiajs/react'; 6 | import { FormEventHandler } from 'react'; 7 | 8 | export default function ForgotPassword({ status }: { status?: string }) { 9 | const { data, setData, post, processing, errors } = useForm({ 10 | email: '', 11 | }); 12 | 13 | const submit: FormEventHandler = (e) => { 14 | e.preventDefault(); 15 | 16 | post(route('password.email')); 17 | }; 18 | 19 | return ( 20 | 21 | 22 | 23 |
24 | Forgot your password? No problem. Just let us know your email 25 | address and we will email you a password reset link that will 26 | allow you to choose a new one. 27 |
28 | 29 | {status && ( 30 |
31 | {status} 32 |
33 | )} 34 | 35 |
36 | setData('email', e.target.value)} 44 | /> 45 | 46 | 47 | 48 |
49 | 50 | Email Password Reset Link 51 | 52 |
53 | 54 |
55 | ); 56 | } 57 | -------------------------------------------------------------------------------- /resources/js/Pages/Auth/Login.tsx: -------------------------------------------------------------------------------- 1 | import Checkbox from '@/Components/Checkbox'; 2 | import InputError from '@/Components/InputError'; 3 | import InputLabel from '@/Components/InputLabel'; 4 | import PrimaryButton from '@/Components/PrimaryButton'; 5 | import TextInput from '@/Components/TextInput'; 6 | import GuestLayout from '@/Layouts/GuestLayout'; 7 | import { Head, Link, useForm } from '@inertiajs/react'; 8 | import { FormEventHandler } from 'react'; 9 | 10 | export default function Login({ 11 | status, 12 | canResetPassword, 13 | }: { 14 | status?: string; 15 | canResetPassword: boolean; 16 | }) { 17 | const { data, setData, post, processing, errors, reset } = useForm({ 18 | email: '', 19 | password: '', 20 | remember: false, 21 | }); 22 | 23 | const submit: FormEventHandler = (e) => { 24 | e.preventDefault(); 25 | 26 | post(route('login'), { 27 | onFinish: () => reset('password'), 28 | }); 29 | }; 30 | 31 | return ( 32 | 33 | 34 | 35 | {status && ( 36 |
37 | {status} 38 |
39 | )} 40 | 41 |
42 |
43 | 44 | 45 | setData('email', e.target.value)} 54 | /> 55 | 56 | 57 |
58 | 59 |
60 | 61 | 62 | setData('password', e.target.value)} 70 | /> 71 | 72 | 73 |
74 | 75 |
76 | 88 |
89 | 90 |
91 | {canResetPassword && ( 92 | 96 | Forgot your password? 97 | 98 | )} 99 | 100 | 101 | Log in 102 | 103 |
104 |
105 |
106 | ); 107 | } 108 | -------------------------------------------------------------------------------- /resources/js/Pages/Auth/Register.tsx: -------------------------------------------------------------------------------- 1 | import InputError from '@/Components/InputError'; 2 | import InputLabel from '@/Components/InputLabel'; 3 | import PrimaryButton from '@/Components/PrimaryButton'; 4 | import TextInput from '@/Components/TextInput'; 5 | import GuestLayout from '@/Layouts/GuestLayout'; 6 | import { Head, Link, useForm } from '@inertiajs/react'; 7 | import { FormEventHandler } from 'react'; 8 | 9 | export default function Register() { 10 | const { data, setData, post, processing, errors, reset } = useForm({ 11 | name: '', 12 | email: '', 13 | password: '', 14 | password_confirmation: '', 15 | }); 16 | 17 | const submit: FormEventHandler = (e) => { 18 | e.preventDefault(); 19 | 20 | post(route('register'), { 21 | onFinish: () => reset('password', 'password_confirmation'), 22 | }); 23 | }; 24 | 25 | return ( 26 | 27 | 28 | 29 |
30 |
31 | 32 | 33 | setData('name', e.target.value)} 41 | required 42 | /> 43 | 44 | 45 |
46 | 47 |
48 | 49 | 50 | setData('email', e.target.value)} 58 | required 59 | /> 60 | 61 | 62 |
63 | 64 |
65 | 66 | 67 | setData('password', e.target.value)} 75 | required 76 | /> 77 | 78 | 79 |
80 | 81 |
82 | 86 | 87 | 95 | setData('password_confirmation', e.target.value) 96 | } 97 | required 98 | /> 99 | 100 | 104 |
105 | 106 |
107 | 111 | Already registered? 112 | 113 | 114 | 115 | Register 116 | 117 |
118 |
119 |
120 | ); 121 | } 122 | -------------------------------------------------------------------------------- /resources/js/Pages/Auth/ResetPassword.tsx: -------------------------------------------------------------------------------- 1 | import InputError from '@/Components/InputError'; 2 | import InputLabel from '@/Components/InputLabel'; 3 | import PrimaryButton from '@/Components/PrimaryButton'; 4 | import TextInput from '@/Components/TextInput'; 5 | import GuestLayout from '@/Layouts/GuestLayout'; 6 | import { Head, useForm } from '@inertiajs/react'; 7 | import { FormEventHandler } from 'react'; 8 | 9 | export default function ResetPassword({ 10 | token, 11 | email, 12 | }: { 13 | token: string; 14 | email: string; 15 | }) { 16 | const { data, setData, post, processing, errors, reset } = useForm({ 17 | token: token, 18 | email: email, 19 | password: '', 20 | password_confirmation: '', 21 | }); 22 | 23 | const submit: FormEventHandler = (e) => { 24 | e.preventDefault(); 25 | 26 | post(route('password.store'), { 27 | onFinish: () => reset('password', 'password_confirmation'), 28 | }); 29 | }; 30 | 31 | return ( 32 | 33 | 34 | 35 |
36 |
37 | 38 | 39 | setData('email', e.target.value)} 47 | /> 48 | 49 | 50 |
51 | 52 |
53 | 54 | 55 | setData('password', e.target.value)} 64 | /> 65 | 66 | 67 |
68 | 69 |
70 | 74 | 75 | 82 | setData('password_confirmation', e.target.value) 83 | } 84 | /> 85 | 86 | 90 |
91 | 92 |
93 | 94 | Reset Password 95 | 96 |
97 |
98 |
99 | ); 100 | } 101 | -------------------------------------------------------------------------------- /resources/js/Pages/Auth/VerifyEmail.tsx: -------------------------------------------------------------------------------- 1 | import PrimaryButton from '@/Components/PrimaryButton'; 2 | import GuestLayout from '@/Layouts/GuestLayout'; 3 | import { Head, Link, useForm } from '@inertiajs/react'; 4 | import { FormEventHandler } from 'react'; 5 | 6 | export default function VerifyEmail({ status }: { status?: string }) { 7 | const { post, processing } = useForm({}); 8 | 9 | const submit: FormEventHandler = (e) => { 10 | e.preventDefault(); 11 | 12 | post(route('verification.send')); 13 | }; 14 | 15 | return ( 16 | 17 | 18 | 19 |
20 | Thanks for signing up! Before getting started, could you verify 21 | your email address by clicking on the link we just emailed to 22 | you? If you didn't receive the email, we will gladly send you 23 | another. 24 |
25 | 26 | {status === 'verification-link-sent' && ( 27 |
28 | A new verification link has been sent to the email address 29 | you provided during registration. 30 |
31 | )} 32 | 33 |
34 |
35 | 36 | Resend Verification Email 37 | 38 | 39 | 45 | Log Out 46 | 47 |
48 |
49 |
50 | ); 51 | } 52 | -------------------------------------------------------------------------------- /resources/js/Pages/Dashboard.tsx: -------------------------------------------------------------------------------- 1 | import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; 2 | import {Head} from '@inertiajs/react'; 3 | 4 | export default function Dashboard() { 5 | return ( 6 | 9 | Dashboard 10 | 11 | } 12 | > 13 | 14 | 15 |
16 |
17 | You're logged in! 18 |
19 |
20 |
21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /resources/js/Pages/Feature/Create.tsx: -------------------------------------------------------------------------------- 1 | import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; 2 | import {Head, useForm} from '@inertiajs/react'; 3 | import {Feature, PaginatedData} from "@/types"; 4 | import FeatureItem from "@/Components/FeatureItem"; 5 | import InputLabel from "@/Components/InputLabel"; 6 | import TextInput from "@/Components/TextInput"; 7 | import InputError from "@/Components/InputError"; 8 | import {FormEventHandler} from "react"; 9 | import TextAreaInput from "@/Components/TextAreaInput"; 10 | import PrimaryButton from "@/Components/PrimaryButton"; 11 | 12 | export default function Show() { 13 | const { 14 | data, 15 | setData, 16 | processing, 17 | errors, 18 | post 19 | } = useForm({ 20 | name: '', 21 | description: '' 22 | }) 23 | 24 | const createFeature: FormEventHandler = (ev) => { 25 | ev.preventDefault(); 26 | 27 | post(route('feature.store'), { 28 | preserveScroll: true 29 | }) 30 | } 31 | 32 | return ( 33 | 36 | Create New Feature 37 | 38 | } 39 | > 40 | 41 | 42 |
43 |
44 |
45 |
46 | 47 | 48 | setData('name', e.target.value)} 53 | required 54 | isFocused 55 | autoComplete="name" 56 | /> 57 | 58 | 59 |
60 | 61 |
62 | 63 | 64 | setData('description', e.target.value)} 70 | /> 71 | 72 | 73 |
74 | 75 |
76 | Save 77 |
78 |
79 |
80 |
81 |
82 | ); 83 | } 84 | -------------------------------------------------------------------------------- /resources/js/Pages/Feature/Edit.tsx: -------------------------------------------------------------------------------- 1 | import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; 2 | import {Head, useForm} from '@inertiajs/react'; 3 | import {Feature, PaginatedData} from "@/types"; 4 | import FeatureItem from "@/Components/FeatureItem"; 5 | import InputLabel from "@/Components/InputLabel"; 6 | import TextInput from "@/Components/TextInput"; 7 | import InputError from "@/Components/InputError"; 8 | import {FormEventHandler} from "react"; 9 | import TextAreaInput from "@/Components/TextAreaInput"; 10 | import PrimaryButton from "@/Components/PrimaryButton"; 11 | 12 | export default function Show({feature}: {feature: Feature}) { 13 | const { 14 | data, 15 | setData, 16 | processing, 17 | errors, 18 | put 19 | } = useForm({ 20 | name: feature.name, 21 | description: feature.description 22 | }) 23 | 24 | const updateFeature: FormEventHandler = (ev) => { 25 | ev.preventDefault(); 26 | 27 | put(route('feature.update', feature.id), { 28 | preserveScroll: true 29 | }) 30 | } 31 | 32 | return ( 33 | 36 | Edit Feature "{feature.name}" 37 | 38 | } 39 | > 40 | 41 | 42 |
43 |
44 |
45 |
46 | 47 | 48 | setData('name', e.target.value)} 53 | required 54 | isFocused 55 | autoComplete="name" 56 | /> 57 | 58 | 59 |
60 | 61 |
62 | 63 | 64 | setData('description', e.target.value)} 70 | /> 71 | 72 | 73 |
74 | 75 |
76 | Save 77 |
78 |
79 |
80 |
81 |
82 | ); 83 | } 84 | -------------------------------------------------------------------------------- /resources/js/Pages/Feature/Index.tsx: -------------------------------------------------------------------------------- 1 | import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; 2 | import {Head, Link, usePage, usePoll} from '@inertiajs/react'; 3 | import {Feature, PageProps, PaginatedData} from "@/types"; 4 | import FeatureItem from "@/Components/FeatureItem"; 5 | import {can} from "@/helpers"; 6 | 7 | export default function Index({auth, features}: PageProps<{features: PaginatedData}>) { 8 | 9 | usePoll(3000); 10 | 11 | return ( 12 | 15 | Features 16 | 17 | } 18 | > 19 | 20 | 21 | {can(auth.user, 'manage_features') &&
22 | 23 | Create New Feature 24 | 25 |
} 26 | {features.data.map(feature => ( 27 | 28 | ))} 29 |
30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /resources/js/Pages/Feature/Show.tsx: -------------------------------------------------------------------------------- 1 | import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; 2 | import {Head} from '@inertiajs/react'; 3 | import {Feature, Comment} from "@/types"; 4 | import FeatureUpvoteDownvote from "@/Components/FeatureUpvoteDownvote"; 5 | import NewCommentForm from "@/Components/NewCommentForm"; 6 | import CommentItem from "@/Components/CommentItem"; 7 | 8 | export default function Show({feature, comments}: { 9 | feature: Feature, comments: Comment[] 10 | }) { 11 | return ( 12 | 15 | Feature {feature.name} 16 | 17 | } 18 | > 19 | 20 | 21 |
22 |
23 | 24 |
25 |

{feature.name}

26 |

{feature.description}

27 | {comments &&
28 | 29 | {comments.map(comment => ( 30 | 31 | ))} 32 |
} 33 |
34 |
35 |
36 |
37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /resources/js/Pages/Profile/Edit.tsx: -------------------------------------------------------------------------------- 1 | import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; 2 | import { PageProps } from '@/types'; 3 | import { Head } from '@inertiajs/react'; 4 | import DeleteUserForm from './Partials/DeleteUserForm'; 5 | import UpdatePasswordForm from './Partials/UpdatePasswordForm'; 6 | import UpdateProfileInformationForm from './Partials/UpdateProfileInformationForm'; 7 | 8 | export default function Edit({ 9 | mustVerifyEmail, 10 | status, 11 | }: PageProps<{ mustVerifyEmail: boolean; status?: string }>) { 12 | return ( 13 | 16 | Profile 17 | 18 | } 19 | > 20 | 21 | 22 |
23 |
24 |
25 | 30 |
31 | 32 |
33 | 34 |
35 | 36 |
37 | 38 |
39 |
40 |
41 |
42 | ); 43 | } 44 | -------------------------------------------------------------------------------- /resources/js/Pages/Profile/Partials/DeleteUserForm.tsx: -------------------------------------------------------------------------------- 1 | import DangerButton from '@/Components/DangerButton'; 2 | import InputError from '@/Components/InputError'; 3 | import InputLabel from '@/Components/InputLabel'; 4 | import Modal from '@/Components/Modal'; 5 | import SecondaryButton from '@/Components/SecondaryButton'; 6 | import TextInput from '@/Components/TextInput'; 7 | import { useForm } from '@inertiajs/react'; 8 | import { FormEventHandler, useRef, useState } from 'react'; 9 | 10 | export default function DeleteUserForm({ 11 | className = '', 12 | }: { 13 | className?: string; 14 | }) { 15 | const [confirmingUserDeletion, setConfirmingUserDeletion] = useState(false); 16 | const passwordInput = useRef(null); 17 | 18 | const { 19 | data, 20 | setData, 21 | delete: destroy, 22 | processing, 23 | reset, 24 | errors, 25 | clearErrors, 26 | } = useForm({ 27 | password: '', 28 | }); 29 | 30 | const confirmUserDeletion = () => { 31 | setConfirmingUserDeletion(true); 32 | }; 33 | 34 | const deleteUser: FormEventHandler = (e) => { 35 | e.preventDefault(); 36 | 37 | destroy(route('profile.destroy'), { 38 | preserveScroll: true, 39 | onSuccess: () => closeModal(), 40 | onError: () => passwordInput.current?.focus(), 41 | onFinish: () => reset(), 42 | }); 43 | }; 44 | 45 | const closeModal = () => { 46 | setConfirmingUserDeletion(false); 47 | 48 | clearErrors(); 49 | reset(); 50 | }; 51 | 52 | return ( 53 |
54 |
55 |

56 | Delete Account 57 |

58 | 59 |

60 | Once your account is deleted, all of its resources and data 61 | will be permanently deleted. Before deleting your account, 62 | please download any data or information that you wish to 63 | retain. 64 |

65 |
66 | 67 | 68 | Delete Account 69 | 70 | 71 | 72 |
73 |

74 | Are you sure you want to delete your account? 75 |

76 | 77 |

78 | Once your account is deleted, all of its resources and 79 | data will be permanently deleted. Please enter your 80 | password to confirm you would like to permanently delete 81 | your account. 82 |

83 | 84 |
85 | 90 | 91 | 98 | setData('password', e.target.value) 99 | } 100 | className="mt-1 block w-3/4" 101 | isFocused 102 | placeholder="Password" 103 | /> 104 | 105 | 109 |
110 | 111 |
112 | 113 | Cancel 114 | 115 | 116 | 117 | Delete Account 118 | 119 |
120 |
121 |
122 |
123 | ); 124 | } 125 | -------------------------------------------------------------------------------- /resources/js/Pages/Profile/Partials/UpdatePasswordForm.tsx: -------------------------------------------------------------------------------- 1 | import InputError from '@/Components/InputError'; 2 | import InputLabel from '@/Components/InputLabel'; 3 | import PrimaryButton from '@/Components/PrimaryButton'; 4 | import TextInput from '@/Components/TextInput'; 5 | import { Transition } from '@headlessui/react'; 6 | import { useForm } from '@inertiajs/react'; 7 | import { FormEventHandler, useRef } from 'react'; 8 | 9 | export default function UpdatePasswordForm({ 10 | className = '', 11 | }: { 12 | className?: string; 13 | }) { 14 | const passwordInput = useRef(null); 15 | const currentPasswordInput = useRef(null); 16 | 17 | const { 18 | data, 19 | setData, 20 | errors, 21 | put, 22 | reset, 23 | processing, 24 | recentlySuccessful, 25 | } = useForm({ 26 | current_password: '', 27 | password: '', 28 | password_confirmation: '', 29 | }); 30 | 31 | const updatePassword: FormEventHandler = (e) => { 32 | e.preventDefault(); 33 | 34 | put(route('password.update'), { 35 | preserveScroll: true, 36 | onSuccess: () => reset(), 37 | onError: (errors) => { 38 | if (errors.password) { 39 | reset('password', 'password_confirmation'); 40 | passwordInput.current?.focus(); 41 | } 42 | 43 | if (errors.current_password) { 44 | reset('current_password'); 45 | currentPasswordInput.current?.focus(); 46 | } 47 | }, 48 | }); 49 | }; 50 | 51 | return ( 52 |
53 |
54 |

55 | Update Password 56 |

57 | 58 |

59 | Ensure your account is using a long, random password to stay 60 | secure. 61 |

62 |
63 | 64 |
65 |
66 | 70 | 71 | 76 | setData('current_password', e.target.value) 77 | } 78 | type="password" 79 | className="mt-1 block w-full" 80 | autoComplete="current-password" 81 | /> 82 | 83 | 87 |
88 | 89 |
90 | 91 | 92 | setData('password', e.target.value)} 97 | type="password" 98 | className="mt-1 block w-full" 99 | autoComplete="new-password" 100 | /> 101 | 102 | 103 |
104 | 105 |
106 | 110 | 111 | 115 | setData('password_confirmation', e.target.value) 116 | } 117 | type="password" 118 | className="mt-1 block w-full" 119 | autoComplete="new-password" 120 | /> 121 | 122 | 126 |
127 | 128 |
129 | Save 130 | 131 | 138 |

139 | Saved. 140 |

141 |
142 |
143 |
144 |
145 | ); 146 | } 147 | -------------------------------------------------------------------------------- /resources/js/Pages/Profile/Partials/UpdateProfileInformationForm.tsx: -------------------------------------------------------------------------------- 1 | import InputError from '@/Components/InputError'; 2 | import InputLabel from '@/Components/InputLabel'; 3 | import PrimaryButton from '@/Components/PrimaryButton'; 4 | import TextInput from '@/Components/TextInput'; 5 | import { Transition } from '@headlessui/react'; 6 | import { Link, useForm, usePage } from '@inertiajs/react'; 7 | import { FormEventHandler } from 'react'; 8 | 9 | export default function UpdateProfileInformation({ 10 | mustVerifyEmail, 11 | status, 12 | className = '', 13 | }: { 14 | mustVerifyEmail: boolean; 15 | status?: string; 16 | className?: string; 17 | }) { 18 | const user = usePage().props.auth.user; 19 | 20 | const { data, setData, patch, errors, processing, recentlySuccessful } = 21 | useForm({ 22 | name: user.name, 23 | email: user.email, 24 | }); 25 | 26 | const submit: FormEventHandler = (e) => { 27 | e.preventDefault(); 28 | 29 | patch(route('profile.update')); 30 | }; 31 | 32 | return ( 33 |
34 |
35 |

36 | Profile Information 37 |

38 | 39 |

40 | Update your account's profile information and email address. 41 |

42 |
43 | 44 |
45 |
46 | 47 | 48 | setData('name', e.target.value)} 53 | required 54 | isFocused 55 | autoComplete="name" 56 | /> 57 | 58 | 59 |
60 | 61 |
62 | 63 | 64 | setData('email', e.target.value)} 70 | required 71 | autoComplete="username" 72 | /> 73 | 74 | 75 |
76 | 77 | {mustVerifyEmail && user.email_verified_at === null && ( 78 |
79 |

80 | Your email address is unverified. 81 | 87 | Click here to re-send the verification email. 88 | 89 |

90 | 91 | {status === 'verification-link-sent' && ( 92 |
93 | A new verification link has been sent to your 94 | email address. 95 |
96 | )} 97 |
98 | )} 99 | 100 |
101 | Save 102 | 103 | 110 |

111 | Saved. 112 |

113 |
114 |
115 |
116 |
117 | ); 118 | } 119 | -------------------------------------------------------------------------------- /resources/js/Pages/User/Edit.tsx: -------------------------------------------------------------------------------- 1 | import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; 2 | import {Head, useForm} from '@inertiajs/react'; 3 | import {User} from "@/types"; 4 | import InputLabel from "@/Components/InputLabel"; 5 | import TextInput from "@/Components/TextInput"; 6 | import InputError from "@/Components/InputError"; 7 | import {FormEventHandler} from "react"; 8 | import PrimaryButton from "@/Components/PrimaryButton"; 9 | import Checkbox from "@/Components/Checkbox"; 10 | import Radio from "@/Components/Radio"; 11 | 12 | export default function Show({roles, user, roleLabels}: { 13 | roles: any, user: User, roleLabels: Record 14 | }) { 15 | console.log(roles) 16 | 17 | const { 18 | data, 19 | setData, 20 | processing, 21 | errors, 22 | put 23 | } = useForm({ 24 | name: user.name, 25 | email: user.email, 26 | roles: user.roles, 27 | }) 28 | 29 | const updateUser: FormEventHandler = (ev) => { 30 | ev.preventDefault(); 31 | 32 | put(route('user.update', user.id), { 33 | preserveScroll: true 34 | }) 35 | } 36 | 37 | const onRoleChange = (ev: any) => { 38 | console.log(ev.target.value, ev.target.checked) 39 | if (ev.target.checked) { 40 | setData('roles', [ev.target.value]) 41 | } 42 | } 43 | 44 | return ( 45 | 48 | Edit User "{user.name}" 49 | 50 | } 51 | > 52 | 53 | 54 |
55 |
56 |
57 |
58 | 59 | 60 | setData('name', e.target.value)} 66 | required 67 | isFocused 68 | autoComplete="name" 69 | /> 70 | 71 | 72 |
73 | 74 |
75 | 76 | 77 | setData('email', e.target.value)} 83 | required 84 | /> 85 | 86 | 87 |
88 | 89 |
90 | 91 | {roles.map((role: any) => ( 92 | 103 | ))} 104 | 105 |
106 | 107 |
108 | Save 109 |
110 |
111 |
112 |
113 |
114 | ); 115 | } 116 | -------------------------------------------------------------------------------- /resources/js/Pages/User/Index.tsx: -------------------------------------------------------------------------------- 1 | import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; 2 | import {Head, Link} from '@inertiajs/react'; 3 | import {User, PageProps, PaginatedData} from "@/types"; 4 | import {can} from "@/helpers"; 5 | 6 | export default function Index({auth, users}: PageProps<{ users: User[] }>) { 7 | 8 | return ( 9 | 12 | Users 13 | 14 | } 15 | > 16 | 17 | 18 |
19 | 20 | 21 | 22 | 25 | 28 | 31 | 34 | 37 | 38 | 39 | 40 | {users.map(user => ( 41 | 44 | 47 | 50 | 53 | 58 | ))} 59 | 60 |
23 | Name 24 | 26 | Email 27 | 29 | Created At 30 | 32 | Roles 33 | 35 | Actions 36 |
42 | {user.name} 43 | 45 | {user.email} 46 | 48 | {user.created_at} 49 | 51 | {user.roles.join(', ')} 52 | 54 | 55 | Edit 56 | 57 |
61 |
62 |
63 | ); 64 | } 65 | -------------------------------------------------------------------------------- /resources/js/app.tsx: -------------------------------------------------------------------------------- 1 | import '../css/app.css'; 2 | import './bootstrap'; 3 | 4 | import { createInertiaApp } from '@inertiajs/react'; 5 | import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'; 6 | import { createRoot, hydrateRoot } from 'react-dom/client'; 7 | 8 | const appName = import.meta.env.VITE_APP_NAME || 'Laravel'; 9 | 10 | createInertiaApp({ 11 | title: (title) => `${title} - ${appName}`, 12 | resolve: (name) => 13 | resolvePageComponent( 14 | `./Pages/${name}.tsx`, 15 | import.meta.glob('./Pages/**/*.tsx'), 16 | ), 17 | setup({ el, App, props }) { 18 | if (import.meta.env.SSR) { 19 | hydrateRoot(el, ); 20 | return; 21 | } 22 | 23 | createRoot(el).render(); 24 | }, 25 | progress: { 26 | color: '#4B5563', 27 | }, 28 | }); 29 | -------------------------------------------------------------------------------- /resources/js/bootstrap.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | window.axios = axios; 3 | 4 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 5 | -------------------------------------------------------------------------------- /resources/js/helpers.ts: -------------------------------------------------------------------------------- 1 | import {User} from "@/types"; 2 | 3 | export function can(user: User, permission: string): boolean { 4 | return user.permissions.includes(permission); 5 | } 6 | 7 | export function hasRole(user: User, role: string): boolean { 8 | return user.roles.includes(role); 9 | } 10 | -------------------------------------------------------------------------------- /resources/js/ssr.tsx: -------------------------------------------------------------------------------- 1 | import { createInertiaApp } from '@inertiajs/react'; 2 | import createServer from '@inertiajs/react/server'; 3 | import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'; 4 | import ReactDOMServer from 'react-dom/server'; 5 | import { RouteName } from 'ziggy-js'; 6 | import { route } from '../../vendor/tightenco/ziggy'; 7 | 8 | const appName = import.meta.env.VITE_APP_NAME || 'Laravel'; 9 | 10 | createServer((page) => 11 | createInertiaApp({ 12 | page, 13 | render: ReactDOMServer.renderToString, 14 | title: (title) => `${title} - ${appName}`, 15 | resolve: (name) => 16 | resolvePageComponent( 17 | `./Pages/${name}.tsx`, 18 | import.meta.glob('./Pages/**/*.tsx'), 19 | ), 20 | setup: ({ App, props }) => { 21 | /* eslint-disable */ 22 | // @ts-expect-error 23 | global.route = (name, params, absolute) => 24 | route(name, params as any, absolute, { 25 | ...page.props.ziggy, 26 | location: new URL(page.props.ziggy.location), 27 | }); 28 | /* eslint-enable */ 29 | 30 | return ; 31 | }, 32 | }), 33 | ); 34 | -------------------------------------------------------------------------------- /resources/js/types/global.d.ts: -------------------------------------------------------------------------------- 1 | import { PageProps as InertiaPageProps } from '@inertiajs/core'; 2 | import { AxiosInstance } from 'axios'; 3 | import { route as ziggyRoute } from 'ziggy-js'; 4 | import { PageProps as AppPageProps } from './'; 5 | 6 | declare global { 7 | interface Window { 8 | axios: AxiosInstance; 9 | } 10 | 11 | /* eslint-disable no-var */ 12 | var route: typeof ziggyRoute; 13 | } 14 | 15 | declare module '@inertiajs/core' { 16 | interface PageProps extends InertiaPageProps, AppPageProps {} 17 | } 18 | -------------------------------------------------------------------------------- /resources/js/types/index.d.ts: -------------------------------------------------------------------------------- 1 | import {Config} from 'ziggy-js'; 2 | 3 | export interface User { 4 | id: number; 5 | name: string; 6 | email: string; 7 | email_verified_at?: string; 8 | created_at: string; 9 | permissions: string[]; 10 | roles: string[] 11 | } 12 | 13 | export type PaginatedData = { 14 | data: T[]; 15 | links: Record 16 | } 17 | 18 | export type Comment = { 19 | id: number; 20 | comment: string; 21 | created_at: string; 22 | user: User 23 | } 24 | 25 | export type Feature = { 26 | id: number; 27 | name: string; 28 | description: string; 29 | user: User; 30 | created_at: string; 31 | upvote_count: number; 32 | user_has_upvoted: boolean; 33 | user_has_downvoted: boolean; 34 | comments: Comment[] 35 | } 36 | 37 | export type PageProps< 38 | T extends Record = Record, 39 | > = T & { 40 | auth: { 41 | user: User; 42 | }; 43 | ziggy: Config & { location: string }; 44 | }; 45 | -------------------------------------------------------------------------------- /resources/js/types/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /resources/views/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{ config('app.name', 'Laravel') }} 8 | 9 | 10 | 11 | 12 | 13 | 14 | @routes 15 | @viteReactRefresh 16 | @vite(['resources/js/app.tsx', "resources/js/Pages/{$page['component']}.tsx"]) 17 | @inertiaHead 18 | 19 | 20 | @inertia 21 | 22 | 23 | -------------------------------------------------------------------------------- /routes/auth.php: -------------------------------------------------------------------------------- 1 | group(function () { 15 | Route::get('register', [RegisteredUserController::class, 'create']) 16 | ->name('register'); 17 | 18 | Route::post('register', [RegisteredUserController::class, 'store']); 19 | 20 | Route::get('login', [AuthenticatedSessionController::class, 'create']) 21 | ->name('login'); 22 | 23 | Route::post('login', [AuthenticatedSessionController::class, 'store']); 24 | 25 | Route::get('forgot-password', [PasswordResetLinkController::class, 'create']) 26 | ->name('password.request'); 27 | 28 | Route::post('forgot-password', [PasswordResetLinkController::class, 'store']) 29 | ->name('password.email'); 30 | 31 | Route::get('reset-password/{token}', [NewPasswordController::class, 'create']) 32 | ->name('password.reset'); 33 | 34 | Route::post('reset-password', [NewPasswordController::class, 'store']) 35 | ->name('password.store'); 36 | }); 37 | 38 | Route::middleware('auth')->group(function () { 39 | Route::get('verify-email', EmailVerificationPromptController::class) 40 | ->name('verification.notice'); 41 | 42 | Route::get('verify-email/{id}/{hash}', VerifyEmailController::class) 43 | ->middleware(['signed', 'throttle:6,1']) 44 | ->name('verification.verify'); 45 | 46 | Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store']) 47 | ->middleware('throttle:6,1') 48 | ->name('verification.send'); 49 | 50 | Route::get('confirm-password', [ConfirmablePasswordController::class, 'show']) 51 | ->name('password.confirm'); 52 | 53 | Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']); 54 | 55 | Route::put('password', [PasswordController::class, 'update'])->name('password.update'); 56 | 57 | Route::post('logout', [AuthenticatedSessionController::class, 'destroy']) 58 | ->name('logout'); 59 | }); 60 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 8 | })->purpose('Display an inspiring quote')->hourly(); 9 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | group(function () { 17 | Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit'); 18 | Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update'); 19 | Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy'); 20 | 21 | Route::middleware(['verified', 'role:' . RolesEnum::Admin->value])->group(function () { 22 | Route::get('/user', [UserController::class, 'index']) 23 | ->name('user.index'); 24 | Route::get('/user/{user}/edit', [UserController::class, 'edit']) 25 | ->name('user.edit'); 26 | Route::put('/user/{user}', [UserController::class, 'update']) 27 | ->name('user.update'); 28 | }); 29 | 30 | Route::middleware([ 31 | 'verified', 32 | sprintf('role:%s|%s|%s', 33 | RolesEnum::User->value, 34 | RolesEnum::Commenter->value, 35 | RolesEnum::Admin->value 36 | ) 37 | ])->group(function () { 38 | Route::get('/dashboard', function () { 39 | return Inertia::render('Dashboard'); 40 | })->name('dashboard'); 41 | 42 | Route::resource('feature', FeatureController::class) 43 | ->except(['index', 'show']) 44 | ->middleware('can:' . PermissionsEnum::ManageFeatures->value); 45 | 46 | Route::get('/feature', [FeatureController::class, 'index']) 47 | ->name('feature.index'); 48 | 49 | Route::get('/feature/{feature}', [FeatureController::class, 'show']) 50 | ->name('feature.show'); 51 | 52 | Route::post('/feature/{feature}/upvote', [UpvoteController::class, 'store']) 53 | ->name('upvote.store'); 54 | Route::delete('/upvote/{feature}', [UpvoteController::class, 'destroy']) 55 | ->name('upvote.destroy'); 56 | 57 | Route::post('/feature/{feature}/comments', [CommentController::class, 'store']) 58 | ->name('comment.store') 59 | ->middleware('can:' . PermissionsEnum::ManageComments->value); 60 | Route::delete('/comment/{comment}', [CommentController::class, 'destroy']) 61 | ->name('comment.destroy') 62 | ->middleware('can:' . PermissionsEnum::ManageComments->value); 63 | }); 64 | }); 65 | 66 | require __DIR__ . '/auth.php'; 67 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !private/ 3 | !public/ 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /storage/app/private/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /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 | import defaultTheme from 'tailwindcss/defaultTheme'; 2 | import forms from '@tailwindcss/forms'; 3 | 4 | /** @type {import('tailwindcss').Config} */ 5 | export default { 6 | content: [ 7 | './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php', 8 | './storage/framework/views/*.php', 9 | './resources/views/**/*.blade.php', 10 | './resources/js/**/*.tsx', 11 | ], 12 | 13 | theme: { 14 | extend: { 15 | fontFamily: { 16 | sans: ['Figtree', ...defaultTheme.fontFamily.sans], 17 | }, 18 | }, 19 | }, 20 | 21 | plugins: [forms], 22 | }; 23 | -------------------------------------------------------------------------------- /tests/Feature/Auth/AuthenticationTest.php: -------------------------------------------------------------------------------- 1 | get('/login'); 7 | 8 | $response->assertStatus(200); 9 | }); 10 | 11 | test('users can authenticate using the login screen', function () { 12 | $user = User::factory()->create(); 13 | 14 | $response = $this->post('/login', [ 15 | 'email' => $user->email, 16 | 'password' => 'password', 17 | ]); 18 | 19 | $this->assertAuthenticated(); 20 | $response->assertRedirect(route('dashboard', absolute: false)); 21 | }); 22 | 23 | test('users can not authenticate with invalid password', function () { 24 | $user = User::factory()->create(); 25 | 26 | $this->post('/login', [ 27 | 'email' => $user->email, 28 | 'password' => 'wrong-password', 29 | ]); 30 | 31 | $this->assertGuest(); 32 | }); 33 | 34 | test('users can logout', function () { 35 | $user = User::factory()->create(); 36 | 37 | $response = $this->actingAs($user)->post('/logout'); 38 | 39 | $this->assertGuest(); 40 | $response->assertRedirect('/'); 41 | }); 42 | -------------------------------------------------------------------------------- /tests/Feature/Auth/EmailVerificationTest.php: -------------------------------------------------------------------------------- 1 | unverified()->create(); 10 | 11 | $response = $this->actingAs($user)->get('/verify-email'); 12 | 13 | $response->assertStatus(200); 14 | }); 15 | 16 | test('email can be verified', function () { 17 | $user = User::factory()->unverified()->create(); 18 | 19 | Event::fake(); 20 | 21 | $verificationUrl = URL::temporarySignedRoute( 22 | 'verification.verify', 23 | now()->addMinutes(60), 24 | ['id' => $user->id, 'hash' => sha1($user->email)] 25 | ); 26 | 27 | $response = $this->actingAs($user)->get($verificationUrl); 28 | 29 | Event::assertDispatched(Verified::class); 30 | expect($user->fresh()->hasVerifiedEmail())->toBeTrue(); 31 | $response->assertRedirect(route('dashboard', absolute: false).'?verified=1'); 32 | }); 33 | 34 | test('email is not verified with invalid hash', function () { 35 | $user = User::factory()->unverified()->create(); 36 | 37 | $verificationUrl = URL::temporarySignedRoute( 38 | 'verification.verify', 39 | now()->addMinutes(60), 40 | ['id' => $user->id, 'hash' => sha1('wrong-email')] 41 | ); 42 | 43 | $this->actingAs($user)->get($verificationUrl); 44 | 45 | expect($user->fresh()->hasVerifiedEmail())->toBeFalse(); 46 | }); 47 | -------------------------------------------------------------------------------- /tests/Feature/Auth/PasswordConfirmationTest.php: -------------------------------------------------------------------------------- 1 | create(); 7 | 8 | $response = $this->actingAs($user)->get('/confirm-password'); 9 | 10 | $response->assertStatus(200); 11 | }); 12 | 13 | test('password can be confirmed', function () { 14 | $user = User::factory()->create(); 15 | 16 | $response = $this->actingAs($user)->post('/confirm-password', [ 17 | 'password' => 'password', 18 | ]); 19 | 20 | $response->assertRedirect(); 21 | $response->assertSessionHasNoErrors(); 22 | }); 23 | 24 | test('password is not confirmed with invalid password', function () { 25 | $user = User::factory()->create(); 26 | 27 | $response = $this->actingAs($user)->post('/confirm-password', [ 28 | 'password' => 'wrong-password', 29 | ]); 30 | 31 | $response->assertSessionHasErrors(); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/Feature/Auth/PasswordResetTest.php: -------------------------------------------------------------------------------- 1 | get('/forgot-password'); 9 | 10 | $response->assertStatus(200); 11 | }); 12 | 13 | test('reset password link can be requested', function () { 14 | Notification::fake(); 15 | 16 | $user = User::factory()->create(); 17 | 18 | $this->post('/forgot-password', ['email' => $user->email]); 19 | 20 | Notification::assertSentTo($user, ResetPassword::class); 21 | }); 22 | 23 | test('reset password screen can be rendered', function () { 24 | Notification::fake(); 25 | 26 | $user = User::factory()->create(); 27 | 28 | $this->post('/forgot-password', ['email' => $user->email]); 29 | 30 | Notification::assertSentTo($user, ResetPassword::class, function ($notification) { 31 | $response = $this->get('/reset-password/'.$notification->token); 32 | 33 | $response->assertStatus(200); 34 | 35 | return true; 36 | }); 37 | }); 38 | 39 | test('password can be reset with valid token', function () { 40 | Notification::fake(); 41 | 42 | $user = User::factory()->create(); 43 | 44 | $this->post('/forgot-password', ['email' => $user->email]); 45 | 46 | Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { 47 | $response = $this->post('/reset-password', [ 48 | 'token' => $notification->token, 49 | 'email' => $user->email, 50 | 'password' => 'password', 51 | 'password_confirmation' => 'password', 52 | ]); 53 | 54 | $response 55 | ->assertSessionHasNoErrors() 56 | ->assertRedirect(route('login')); 57 | 58 | return true; 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /tests/Feature/Auth/PasswordUpdateTest.php: -------------------------------------------------------------------------------- 1 | create(); 8 | 9 | $response = $this 10 | ->actingAs($user) 11 | ->from('/profile') 12 | ->put('/password', [ 13 | 'current_password' => 'password', 14 | 'password' => 'new-password', 15 | 'password_confirmation' => 'new-password', 16 | ]); 17 | 18 | $response 19 | ->assertSessionHasNoErrors() 20 | ->assertRedirect('/profile'); 21 | 22 | $this->assertTrue(Hash::check('new-password', $user->refresh()->password)); 23 | }); 24 | 25 | test('correct password must be provided to update password', function () { 26 | $user = User::factory()->create(); 27 | 28 | $response = $this 29 | ->actingAs($user) 30 | ->from('/profile') 31 | ->put('/password', [ 32 | 'current_password' => 'wrong-password', 33 | 'password' => 'new-password', 34 | 'password_confirmation' => 'new-password', 35 | ]); 36 | 37 | $response 38 | ->assertSessionHasErrors('current_password') 39 | ->assertRedirect('/profile'); 40 | }); 41 | -------------------------------------------------------------------------------- /tests/Feature/Auth/RegistrationTest.php: -------------------------------------------------------------------------------- 1 | get('/register'); 5 | 6 | $response->assertStatus(200); 7 | }); 8 | 9 | test('new users can register', function () { 10 | $response = $this->post('/register', [ 11 | 'name' => 'Test User', 12 | 'email' => 'test@example.com', 13 | 'password' => 'password', 14 | 'password_confirmation' => 'password', 15 | ]); 16 | 17 | $this->assertAuthenticated(); 18 | $response->assertRedirect(route('dashboard', absolute: false)); 19 | }); 20 | -------------------------------------------------------------------------------- /tests/Feature/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 5 | 6 | $response->assertStatus(200); 7 | }); 8 | -------------------------------------------------------------------------------- /tests/Feature/ProfileTest.php: -------------------------------------------------------------------------------- 1 | create(); 7 | 8 | $response = $this 9 | ->actingAs($user) 10 | ->get('/profile'); 11 | 12 | $response->assertOk(); 13 | }); 14 | 15 | test('profile information can be updated', function () { 16 | $user = User::factory()->create(); 17 | 18 | $response = $this 19 | ->actingAs($user) 20 | ->patch('/profile', [ 21 | 'name' => 'Test User', 22 | 'email' => 'test@example.com', 23 | ]); 24 | 25 | $response 26 | ->assertSessionHasNoErrors() 27 | ->assertRedirect('/profile'); 28 | 29 | $user->refresh(); 30 | 31 | $this->assertSame('Test User', $user->name); 32 | $this->assertSame('test@example.com', $user->email); 33 | $this->assertNull($user->email_verified_at); 34 | }); 35 | 36 | test('email verification status is unchanged when the email address is unchanged', function () { 37 | $user = User::factory()->create(); 38 | 39 | $response = $this 40 | ->actingAs($user) 41 | ->patch('/profile', [ 42 | 'name' => 'Test User', 43 | 'email' => $user->email, 44 | ]); 45 | 46 | $response 47 | ->assertSessionHasNoErrors() 48 | ->assertRedirect('/profile'); 49 | 50 | $this->assertNotNull($user->refresh()->email_verified_at); 51 | }); 52 | 53 | test('user can delete their account', function () { 54 | $user = User::factory()->create(); 55 | 56 | $response = $this 57 | ->actingAs($user) 58 | ->delete('/profile', [ 59 | 'password' => 'password', 60 | ]); 61 | 62 | $response 63 | ->assertSessionHasNoErrors() 64 | ->assertRedirect('/'); 65 | 66 | $this->assertGuest(); 67 | $this->assertNull($user->fresh()); 68 | }); 69 | 70 | test('correct password must be provided to delete account', function () { 71 | $user = User::factory()->create(); 72 | 73 | $response = $this 74 | ->actingAs($user) 75 | ->from('/profile') 76 | ->delete('/profile', [ 77 | 'password' => 'wrong-password', 78 | ]); 79 | 80 | $response 81 | ->assertSessionHasErrors('password') 82 | ->assertRedirect('/profile'); 83 | 84 | $this->assertNotNull($user->fresh()); 85 | }); 86 | -------------------------------------------------------------------------------- /tests/Pest.php: -------------------------------------------------------------------------------- 1 | extend(Tests\TestCase::class) 15 | ->use(Illuminate\Foundation\Testing\RefreshDatabase::class) 16 | ->in('Feature'); 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Expectations 21 | |-------------------------------------------------------------------------- 22 | | 23 | | When you're writing tests, you often need to check that values meet certain conditions. The 24 | | "expect()" function gives you access to a set of "expectations" methods that you can use 25 | | to assert different things. Of course, you may extend the Expectation API at any time. 26 | | 27 | */ 28 | 29 | expect()->extend('toBeOne', function () { 30 | return $this->toBe(1); 31 | }); 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Functions 36 | |-------------------------------------------------------------------------- 37 | | 38 | | While Pest is very powerful out-of-the-box, you may have some testing code specific to your 39 | | project that you don't want to repeat in every file. Here you can also expose helpers as 40 | | global functions to help you to reduce the number of lines of code in your test files. 41 | | 42 | */ 43 | 44 | function something() 45 | { 46 | // .. 47 | } 48 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | toBeTrue(); 5 | }); 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "module": "ESNext", 5 | "moduleResolution": "bundler", 6 | "jsx": "react-jsx", 7 | "strict": true, 8 | "isolatedModules": true, 9 | "target": "ESNext", 10 | "esModuleInterop": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "skipLibCheck": true, 13 | "noEmit": true, 14 | "paths": { 15 | "@/*": ["./resources/js/*"], 16 | "ziggy-js": ["./vendor/tightenco/ziggy"] 17 | } 18 | }, 19 | "include": ["resources/js/**/*.ts", "resources/js/**/*.tsx", "resources/js/**/*.d.ts"] 20 | } 21 | -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import laravel from 'laravel-vite-plugin'; 3 | import react from '@vitejs/plugin-react'; 4 | 5 | export default defineConfig({ 6 | plugins: [ 7 | laravel({ 8 | input: 'resources/js/app.tsx', 9 | ssr: 'resources/js/ssr.tsx', 10 | refresh: true, 11 | }), 12 | react(), 13 | ], 14 | }); 15 | --------------------------------------------------------------------------------