From c814a6ade22fac8c419d99b4a5c0a64520617504 Mon Sep 17 00:00:00 2001 From: Curtis Delicata Date: Sat, 20 Jul 2024 14:51:08 +0000 Subject: [PATCH] Upgrade composer and npm --- app/Actions/Fortify/CreateNewUser.php | 35 +++++++++++++++---- .../Fortify/CreateNewUserWithTeams.php | 2 +- app/Filament/App/Pages/CreateTeam.php | 4 +-- config/app.php | 7 ++-- config/jetstream.php | 4 +-- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/app/Actions/Fortify/CreateNewUser.php b/app/Actions/Fortify/CreateNewUser.php index 7bf18d0a..ecd47a2f 100644 --- a/app/Actions/Fortify/CreateNewUser.php +++ b/app/Actions/Fortify/CreateNewUser.php @@ -2,7 +2,9 @@ namespace App\Actions\Fortify; +use App\Models\Team; use App\Models\User; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; @@ -15,12 +17,12 @@ class CreateNewUser implements CreatesNewUsers /** * Validate and create a newly registered user. * - * @param array $input + * @param array $input */ public function create(array $input): User { Validator::make($input, [ - 'name' => ['required', 'string', 'max:255'], + 'name' => ['required', 'string', 'max:255'], 'email' => [ 'required', 'string', @@ -31,10 +33,29 @@ public function create(array $input): User 'password' => $this->passwordRules(), ])->validate(); - return User::create([ - 'name' => $input['name'], - 'email' => $input['email'], - 'password' => Hash::make($input['password']), - ]); + return DB::transaction(function () use ($input) { + return tap(User::create([ + 'name' => $input['name'], + 'email' => $input['email'], + 'password' => Hash::make($input['password']), + ]), function (User $user) { + $team = $this->createTeam($user); + $user->switchTeam($team); + setPermissionsTeamId($team->id); + $user->assignRole('free'); + }); + }); + } + + /** + * Create a personal team for the user. + */ + protected function createTeam(User $user) + { + return $user->ownedTeams()->save(Team::forceCreate([ + 'user_id' => $user->id, + 'name' => explode(' ', $user->name, 2)[0]."'s Team", + 'personal_team' => true, + ])); } } diff --git a/app/Actions/Fortify/CreateNewUserWithTeams.php b/app/Actions/Fortify/CreateNewUserWithTeams.php index 9788471d..8434913b 100644 --- a/app/Actions/Fortify/CreateNewUserWithTeams.php +++ b/app/Actions/Fortify/CreateNewUserWithTeams.php @@ -10,7 +10,7 @@ use Laravel\Fortify\Contracts\CreatesNewUsers; use Laravel\Jetstream\Jetstream; -class CreateNewUser implements CreatesNewUsers +class CreateNewUserWithTeams implements CreatesNewUsers { use PasswordValidationRules; diff --git a/app/Filament/App/Pages/CreateTeam.php b/app/Filament/App/Pages/CreateTeam.php index a1e5459d..28bbe799 100644 --- a/app/Filament/App/Pages/CreateTeam.php +++ b/app/Filament/App/Pages/CreateTeam.php @@ -2,11 +2,11 @@ namespace App\Filament\App\Pages; -use App\Models\Team; use App\Models\User; use Filament\Facades\Filament; use Filament\Forms\Components\TextInput; use Filament\Pages\Tenancy\RegisterTenant; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Auth; class CreateTeam extends RegisterTenant @@ -32,7 +32,7 @@ protected function getFormSchema(): array ]; } - protected function handleRegistration(array $data): Team + protected function handleRegistration(array $data): Model { return app(\App\Actions\Jetstream\CreateTeam::class)->create(auth()->user(), $data); } diff --git a/config/app.php b/config/app.php index 06df67d3..430c0dc8 100644 --- a/config/app.php +++ b/config/app.php @@ -57,7 +57,7 @@ 'url' => env('APP_URL', 'http://localhost'), - 'asset_url' => env('ASSET_URL'), + 'asset_url' => env('ASSET_URL', '/'), /* |-------------------------------------------------------------------------- @@ -160,7 +160,6 @@ * Package Service Providers... */ JoelButcher\Socialstream\Filament\SocialstreamPanelProvider::class, - JoelButcher\Socialstream\Filament\SocialstreamPanelProvider::class, /* * Application Service Providers... @@ -172,6 +171,10 @@ App\Providers\Filament\AdminPanelProvider::class, App\Providers\Filament\AppPanelProvider::class, App\Providers\RouteServiceProvider::class, + + App\Providers\TeamServiceProvider::class, + App\Providers\JetstreamServiceProvider::class, + App\Providers\FortifyServiceProvider::class, ])->toArray(), /* diff --git a/config/jetstream.php b/config/jetstream.php index 7782d051..32f1a315 100644 --- a/config/jetstream.php +++ b/config/jetstream.php @@ -16,7 +16,7 @@ | */ - 'stack' => 'livewire', + 'stack' => 'inertia', /* |-------------------------------------------------------------------------- @@ -60,7 +60,7 @@ 'features' => [ // Features::termsAndPrivacyPolicy(), // Features::profilePhotos(), - Features::api(), + // Features::api(), Features::teams(['invitations' => true]), Features::accountDeletion(), ],