Skip to content

Commit 249dfd0

Browse files
committed
jetstream
1 parent 774ff85 commit 249dfd0

File tree

131 files changed

+7630
-379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+7630
-379
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.phpunit.cache
2+
/bootstrap/ssr
23
/node_modules
34
/public/build
45
/public/hot

README.md

+12-55
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,23 @@
1-
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
1+
# Laravel JJetstream React (Typescript) Starter Kit
22

3-
<p align="center">
4-
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
5-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
6-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
7-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
8-
</p>
3+
## Introduction
94

10-
## About Laravel
5+
A React starter kit based on Laravel Jetstream which provides a robust, modern starting point for building Laravel applications with a React frontend using [Inertia](https://inertiajs.com).
116

12-
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
7+
Inertia allows you to build modern, single-page React applications using classic server-side routing and controllers. This lets you enjoy the frontend power of React combined with the incredible backend productivity of Laravel and lightning-fast Vite compilation.
138

14-
- [Simple, fast routing engine](https://laravel.com/docs/routing).
15-
- [Powerful dependency injection container](https://laravel.com/docs/container).
16-
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
17-
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
18-
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
19-
- [Robust background job processing](https://laravel.com/docs/queues).
20-
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
9+
This React starter kit utilizes React 19, TypeScript, Tailwind, and the [HeadlessUI](https://headlessui.com/) component library.
2110

22-
Laravel is accessible, powerful, and provides tools required for large, robust applications.
11+
## Getting Started
2312

24-
## Learning Laravel
13+
```bash
14+
laravel new --using=adrum/laravel-react-mantine-starter-kit
15+
```
2516

26-
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
17+
## Documentation
2718

28-
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
29-
30-
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
31-
32-
## Laravel Sponsors
33-
34-
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
35-
36-
### Premium Partners
37-
38-
- **[Vehikl](https://vehikl.com/)**
39-
- **[Tighten Co.](https://tighten.co)**
40-
- **[WebReinvent](https://webreinvent.com/)**
41-
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
42-
- **[64 Robots](https://64robots.com)**
43-
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
44-
- **[Cyber-Duck](https://cyber-duck.co.uk)**
45-
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
46-
- **[Jump24](https://jump24.co.uk)**
47-
- **[Redberry](https://redberry.international/laravel/)**
48-
- **[Active Logic](https://activelogic.com)**
49-
- **[byte5](https://byte5.de)**
50-
- **[OP.GG](https://op.gg)**
51-
52-
## Contributing
53-
54-
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
55-
56-
## Code of Conduct
57-
58-
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
59-
60-
## Security Vulnerabilities
61-
62-
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [[email protected]](mailto:[email protected]). All security vulnerabilities will be promptly addressed.
19+
Documentation for Official Laravel starter kits can be found on the [Laravel website](https://laravel.com/docs/starter-kits). This project is not an official Laravel starter kit, but most of the documentation for the React starter kit should apply to this project as well.
6320

6421
## License
6522

66-
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
23+
The Laravel + React (Mantine) starter kit is open-sourced software licensed under the MIT license.

app/Actions/Fortify/CreateNewUser.php

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\Team;
6+
use App\Models\User;
7+
use Illuminate\Support\Facades\DB;
8+
use Illuminate\Support\Facades\Hash;
9+
use Illuminate\Support\Facades\Validator;
10+
use Laravel\Fortify\Contracts\CreatesNewUsers;
11+
use Laravel\Jetstream\Jetstream;
12+
13+
class CreateNewUser implements CreatesNewUsers
14+
{
15+
use PasswordValidationRules;
16+
17+
/**
18+
* Create a newly registered user.
19+
*
20+
* @param array<string, string> $input
21+
*/
22+
public function create(array $input): User
23+
{
24+
Validator::make($input, [
25+
'name' => ['required', 'string', 'max:255'],
26+
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
27+
'password' => $this->passwordRules(),
28+
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
29+
])->validate();
30+
31+
return DB::transaction(function () use ($input) {
32+
return tap(User::create([
33+
'name' => $input['name'],
34+
'email' => $input['email'],
35+
'password' => Hash::make($input['password']),
36+
]), function (User $user) {
37+
$this->createTeam($user);
38+
});
39+
});
40+
}
41+
42+
/**
43+
* Create a personal team for the user.
44+
*/
45+
protected function createTeam(User $user): void
46+
{
47+
$user->ownedTeams()->save(Team::forceCreate([
48+
'user_id' => $user->id,
49+
'name' => explode(' ', $user->name, 2)[0]."'s Team",
50+
'personal_team' => true,
51+
]));
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use Illuminate\Validation\Rules\Password;
6+
7+
trait PasswordValidationRules
8+
{
9+
/**
10+
* Get the validation rules used to validate passwords.
11+
*
12+
* @return array<int, \Illuminate\Contracts\Validation\Rule|array<mixed>|string>
13+
*/
14+
protected function passwordRules(): array
15+
{
16+
return ['required', 'string', Password::default(), 'confirmed'];
17+
}
18+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Support\Facades\Validator;
8+
use Laravel\Fortify\Contracts\ResetsUserPasswords;
9+
10+
class ResetUserPassword implements ResetsUserPasswords
11+
{
12+
use PasswordValidationRules;
13+
14+
/**
15+
* Validate and reset the user's forgotten password.
16+
*
17+
* @param array<string, string> $input
18+
*/
19+
public function reset(User $user, array $input): void
20+
{
21+
Validator::make($input, [
22+
'password' => $this->passwordRules(),
23+
])->validate();
24+
25+
$user->forceFill([
26+
'password' => Hash::make($input['password']),
27+
])->save();
28+
}
29+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Support\Facades\Validator;
8+
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
9+
10+
class UpdateUserPassword implements UpdatesUserPasswords
11+
{
12+
use PasswordValidationRules;
13+
14+
/**
15+
* Validate and update the user's password.
16+
*
17+
* @param array<string, string> $input
18+
*/
19+
public function update(User $user, array $input): void
20+
{
21+
Validator::make($input, [
22+
'current_password' => ['required', 'string', 'current_password:web'],
23+
'password' => $this->passwordRules(),
24+
], [
25+
'current_password.current_password' => __('The provided password does not match your current password.'),
26+
])->validateWithBag('updatePassword');
27+
28+
$user->forceFill([
29+
'password' => Hash::make($input['password']),
30+
])->save();
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Contracts\Auth\MustVerifyEmail;
7+
use Illuminate\Support\Facades\Validator;
8+
use Illuminate\Validation\Rule;
9+
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
10+
11+
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
12+
{
13+
/**
14+
* Validate and update the given user's profile information.
15+
*
16+
* @param array<string, mixed> $input
17+
*/
18+
public function update(User $user, array $input): void
19+
{
20+
Validator::make($input, [
21+
'name' => ['required', 'string', 'max:255'],
22+
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
23+
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
24+
])->validateWithBag('updateProfileInformation');
25+
26+
if (isset($input['photo'])) {
27+
$user->updateProfilePhoto($input['photo']);
28+
}
29+
30+
if ($input['email'] !== $user->email &&
31+
$user instanceof MustVerifyEmail) {
32+
$this->updateVerifiedUser($user, $input);
33+
} else {
34+
$user->forceFill([
35+
'name' => $input['name'],
36+
'email' => $input['email'],
37+
])->save();
38+
}
39+
}
40+
41+
/**
42+
* Update the given verified user's profile information.
43+
*
44+
* @param array<string, string> $input
45+
*/
46+
protected function updateVerifiedUser(User $user, array $input): void
47+
{
48+
$user->forceFill([
49+
'name' => $input['name'],
50+
'email' => $input['email'],
51+
'email_verified_at' => null,
52+
])->save();
53+
54+
$user->sendEmailVerificationNotification();
55+
}
56+
}
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace App\Actions\Jetstream;
4+
5+
use App\Models\Team;
6+
use App\Models\User;
7+
use Closure;
8+
use Illuminate\Support\Facades\Gate;
9+
use Illuminate\Support\Facades\Validator;
10+
use Laravel\Jetstream\Contracts\AddsTeamMembers;
11+
use Laravel\Jetstream\Events\AddingTeamMember;
12+
use Laravel\Jetstream\Events\TeamMemberAdded;
13+
use Laravel\Jetstream\Jetstream;
14+
use Laravel\Jetstream\Rules\Role;
15+
16+
class AddTeamMember implements AddsTeamMembers
17+
{
18+
/**
19+
* Add a new team member to the given team.
20+
*/
21+
public function add(User $user, Team $team, string $email, ?string $role = null): void
22+
{
23+
Gate::forUser($user)->authorize('addTeamMember', $team);
24+
25+
$this->validate($team, $email, $role);
26+
27+
$newTeamMember = Jetstream::findUserByEmailOrFail($email);
28+
29+
AddingTeamMember::dispatch($team, $newTeamMember);
30+
31+
$team->users()->attach(
32+
$newTeamMember, ['role' => $role]
33+
);
34+
35+
TeamMemberAdded::dispatch($team, $newTeamMember);
36+
}
37+
38+
/**
39+
* Validate the add member operation.
40+
*/
41+
protected function validate(Team $team, string $email, ?string $role): void
42+
{
43+
Validator::make([
44+
'email' => $email,
45+
'role' => $role,
46+
], $this->rules(), [
47+
'email.exists' => __('We were unable to find a registered user with this email address.'),
48+
])->after(
49+
$this->ensureUserIsNotAlreadyOnTeam($team, $email)
50+
)->validateWithBag('addTeamMember');
51+
}
52+
53+
/**
54+
* Get the validation rules for adding a team member.
55+
*
56+
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
57+
*/
58+
protected function rules(): array
59+
{
60+
return array_filter([
61+
'email' => ['required', 'email', 'exists:users'],
62+
'role' => Jetstream::hasRoles()
63+
? ['required', 'string', new Role]
64+
: null,
65+
]);
66+
}
67+
68+
/**
69+
* Ensure that the user is not already on the team.
70+
*/
71+
protected function ensureUserIsNotAlreadyOnTeam(Team $team, string $email): Closure
72+
{
73+
return function ($validator) use ($team, $email) {
74+
$validator->errors()->addIf(
75+
$team->hasUserWithEmail($email),
76+
'email',
77+
__('This user already belongs to the team.')
78+
);
79+
};
80+
}
81+
}

app/Actions/Jetstream/CreateTeam.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Actions\Jetstream;
4+
5+
use App\Models\Team;
6+
use App\Models\User;
7+
use Illuminate\Support\Facades\Gate;
8+
use Illuminate\Support\Facades\Validator;
9+
use Laravel\Jetstream\Contracts\CreatesTeams;
10+
use Laravel\Jetstream\Events\AddingTeam;
11+
use Laravel\Jetstream\Jetstream;
12+
13+
class CreateTeam implements CreatesTeams
14+
{
15+
/**
16+
* Validate and create a new team for the given user.
17+
*
18+
* @param array<string, string> $input
19+
*/
20+
public function create(User $user, array $input): Team
21+
{
22+
Gate::forUser($user)->authorize('create', Jetstream::newTeamModel());
23+
24+
Validator::make($input, [
25+
'name' => ['required', 'string', 'max:255'],
26+
])->validateWithBag('createTeam');
27+
28+
AddingTeam::dispatch($user);
29+
30+
$user->switchTeam($team = $user->ownedTeams()->create([
31+
'name' => $input['name'],
32+
'personal_team' => false,
33+
]));
34+
35+
return $team;
36+
}
37+
}

0 commit comments

Comments
 (0)