PHP Classes

File: app/Actions/Fortify/UpdateUserProfileInformation.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Jaxon DB Admin   app/Actions/Fortify/UpdateUserProfileInformation.php   Download  
File: app/Actions/Fortify/UpdateUserProfileInformation.php
Role: Class source
Content typex: text/plain
Description: Class source
Class: Jaxon DB Admin
Web application to manage SQL of databases
Author: By
Last change: Update of app/Actions/Fortify/UpdateUserProfileInformation.php
Date: 1 month ago
Size: 1,634 bytes
 

Contents

Class file image Download
<?php

namespace App\Actions\Fortify;

use
App\Models\User;
use
Illuminate\Contracts\Auth\MustVerifyEmail;
use
Illuminate\Support\Facades\Validator;
use
Illuminate\Validation\Rule;
use
Laravel\Fortify\Contracts\UpdatesUserProfileInformation;

class
UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
   
/**
     * Validate and update the given user's profile information.
     *
     * @param array<string, string> $input
     */
   
public function update(User $user, array $input): void
   
{
       
Validator::make($input, [
           
'name' => ['required', 'string', 'max:255'],

           
'email' => [
               
'required',
               
'string',
               
'email',
               
'max:255',
               
Rule::unique('users')->ignore($user->id),
            ],
        ])->
validateWithBag('updateProfileInformation');

        if (
$input['email'] !== $user->email &&
           
$user instanceof MustVerifyEmail) {
           
$this->updateVerifiedUser($user, $input);
        } else {
           
$user->forceFill([
               
'name' => $input['name'],
               
'email' => $input['email'],
            ])->
save();
        }
    }

   
/**
     * Update the given verified user's profile information.
     *
     * @param array<string, string> $input
     */
   
protected function updateVerifiedUser(User $user, array $input): void
   
{
       
$user->forceFill([
           
'name' => $input['name'],
           
'email' => $input['email'],
           
'email_verified_at' => null,
        ])->
save();

       
$user->sendEmailVerificationNotification();
    }
}