Skip to content

Commit

Permalink
Remove migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisdelicata committed Jun 13, 2024
1 parent 34c0f1b commit 3cbfafd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 40 deletions.
41 changes: 14 additions & 27 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,39 @@

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;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Laravel\Jetstream\Jetstream;

class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules;

/**
* Create a newly registered user.
* Validate and create a newly registered user.
*
* @param array<string, string> $input
*/
public function create(array $input): User
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'email' => [
'required',
'string',
'email',
'max:255',
Rule::unique(User::class),
],
'password' => $this->passwordRules(),
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
])->validate();

return DB::transaction(function () use ($input) {
return tap(User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]), function (User $user) {
$this->createTeam($user);
});
});
}

/**
* Create a personal team for the user.
*/
protected function createTeam(User $user): void
{
$user->ownedTeams()->save(Team::forceCreate([
'user_id' => $user->id,
'name' => explode(' ', $user->name, 2)[0]."'s Team",
'personal_team' => true,
]));
return User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
}
}
16 changes: 9 additions & 7 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation
/**
* Validate and update the given user's profile information.
*
* @param array<string, mixed> $input
* @param array<string, string> $input
*/
public function update(User $user, array $input): void
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
])->validateWithBag('updateProfileInformation');

if (isset($input['photo'])) {
$user->updateProfilePhoto($input['photo']);
}
'email' => [
'required',
'string',
'email',
'max:255',
Rule::unique('users')->ignore($user->id),
],
])->validateWithBag('updateProfileInformation');

if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
Expand Down
1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
* Package Service Providers...
*/
JoelButcher\Socialstream\Filament\SocialstreamPanelProvider::class,
JoelButcher\Socialstream\Filament\SocialstreamPanelProvider::class,

/*
* Application Service Providers...
Expand Down
2 changes: 1 addition & 1 deletion config/fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
'features' => [
Features::registration(),
Features::resetPasswords(),
Features::emailVerification(),
// Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication([
Expand Down
6 changes: 3 additions & 3 deletions config/jetstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
|
*/

'stack' => 'livewire',
'stack' => 'inertia',

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -60,8 +60,8 @@
'features' => [
// Features::termsAndPrivacyPolicy(),
// Features::profilePhotos(),
Features::api(),
Features::teams(['invitations' => true]),
// Features::api(),
// Features::teams(['invitations' => true]),
Features::accountDeletion(),
],

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
Route::get('/team-invitations/{invitation}', [TeamInvitationController::class, 'accept'])
->middleware(['signed', 'verified', 'auth', AuthenticateSession::class])
->name('team-invitations.accept');
require __DIR__.'/socialstream.php';
require __DIR__.'/socialstream.php';require __DIR__.'/socialstream.php';

0 comments on commit 3cbfafd

Please sign in to comment.