progetto di test della creazione di un progetto basato sul framework laravel e aggiunta form login e register utilizzando breeze
filippo.bertilotti
2024-04-17 637d67e9cd8572ca9f637a0293b06b16d6f287c6
commit | author | age
f7d0ce 1 <?php
F 2
3 use App\Models\User;
4 use App\Providers\RouteServiceProvider;
5 use Illuminate\Support\Facades\Auth;
6 use Illuminate\Support\Facades\Session;
7 use Illuminate\Validation\Rule;
8 use Livewire\Volt\Component;
9
10 new class extends Component
11 {
12     public string $name = '';
13     public string $email = '';
14
15     /**
16      * Mount the component.
17      */
18     public function mount(): void
19     {
20         $this->name = Auth::user()->name;
21         $this->email = Auth::user()->email;
22     }
23
24     /**
25      * Update the profile information for the currently authenticated user.
26      */
27     public function updateProfileInformation(): void
28     {
29         $user = Auth::user();
30
31         $validated = $this->validate([
32             'name' => ['required', 'string', 'max:255'],
33             'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($user->id)],
34         ]);
35
36         $user->fill($validated);
37
38         if ($user->isDirty('email')) {
39             $user->email_verified_at = null;
40         }
41
42         $user->save();
43
44         $this->dispatch('profile-updated', name: $user->name);
45     }
46
47     /**
48      * Send an email verification notification to the current user.
49      */
50     public function sendVerification(): void
51     {
52         $user = Auth::user();
53
54         if ($user->hasVerifiedEmail()) {
55             $this->redirectIntended(default: RouteServiceProvider::HOME);
56
57             return;
58         }
59
60         $user->sendEmailVerificationNotification();
61
62         Session::flash('status', 'verification-link-sent');
63     }
64 }; ?>
65
66 <section>
67     <header>
68         <h2 class="text-lg font-medium text-gray-900">
69             {{ __('Profile Information') }}
70         </h2>
71
72         <p class="mt-1 text-sm text-gray-600">
73             {{ __("Update your account's profile information and email address.") }}
74         </p>
75     </header>
76
77     <form wire:submit="updateProfileInformation" class="mt-6 space-y-6">
78         <div>
79             <x-input-label for="name" :value="__('Name')" />
80             <x-text-input wire:model="name" id="name" name="name" type="text" class="mt-1 block w-full" required autofocus autocomplete="name" />
81             <x-input-error class="mt-2" :messages="$errors->get('name')" />
82         </div>
83
84         <div>
85             <x-input-label for="email" :value="__('Email')" />
86             <x-text-input wire:model="email" id="email" name="email" type="email" class="mt-1 block w-full" required autocomplete="username" />
87             <x-input-error class="mt-2" :messages="$errors->get('email')" />
88
89             @if (auth()->user() instanceof \Illuminate\Contracts\Auth\MustVerifyEmail && ! auth()->user()->hasVerifiedEmail())
90                 <div>
91                     <p class="text-sm mt-2 text-gray-800">
92                         {{ __('Your email address is unverified.') }}
93
94                         <button wire:click.prevent="sendVerification" class="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
95                             {{ __('Click here to re-send the verification email.') }}
96                         </button>
97                     </p>
98
99                     @if (session('status') === 'verification-link-sent')
100                         <p class="mt-2 font-medium text-sm text-green-600">
101                             {{ __('A new verification link has been sent to your email address.') }}
102                         </p>
103                     @endif
104                 </div>
105             @endif
106         </div>
107
108         <div class="flex items-center gap-4">
109             <x-primary-button>{{ __('Save') }}</x-primary-button>
110
111             <x-action-message class="me-3" on="profile-updated">
112                 {{ __('Saved.') }}
113             </x-action-message>
114         </div>
115     </form>
116 </section>