<?php
namespace App\Filament\Pages;
use App\Models\User;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Filament\Schemas\Components\Form;
use Filament\Support\Exceptions\Halt;
use Notification;
class EditProfile extends Page implements HasForms
{
use InteractsWithForms;
public ?array $data = [];
protected string $view = 'filament.pages.edit-profile';
protected static string|BackedEnum|null $navigationIcon = Heroicon::PencilSquare;
protected static ?string $slug = 'profile';
public function mount(): void
{
$this->form->fill(auth()->user()->attributesToArray());
}
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->label('Hotel Name')
->required(),
TextInput::make('email')
->label('Email Address')
->email()
->required(),
TextInput::make('password')
->label('Password')
->password()
->dehydrated(false)
->nullable(),
TextInput::make('password_confirmation')
->label('Confirm Password')
->password()
->dehydrated(false)
->nullable(),
])
->statePath('data');
}
protected function getFormActions(): array
{
return [
Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->submit('save'),
];
}
public function save(): void
{
try {
$data = $this->form->getState();
User::where('id', auth()->user()->id)->update($data);
} catch (Halt $exception) {
return;
}
Notification::make()
->success()
->title(__('filament-panels::resources/pages/edit-record.notifications.saved.title'))
->send();
}
}
<?php
namespace App\Filament\Pages;
use App\Models\User;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Filament\Schemas\Components\Form;
use Filament\Support\Exceptions\Halt;
use Notification;
class EditProfile extends Page implements HasForms
{
use InteractsWithForms;
public ?array $data = [];
protected string $view = 'filament.pages.edit-profile';
protected static string|BackedEnum|null $navigationIcon = Heroicon::PencilSquare;
protected static ?string $slug = 'profile';
public function mount(): void
{
$this->form->fill(auth()->user()->attributesToArray());
}
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->label('Hotel Name')
->required(),
TextInput::make('email')
->label('Email Address')
->email()
->required(),
TextInput::make('password')
->label('Password')
->password()
->dehydrated(false)
->nullable(),
TextInput::make('password_confirmation')
->label('Confirm Password')
->password()
->dehydrated(false)
->nullable(),
])
->statePath('data');
}
protected function getFormActions(): array
{
return [
Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->submit('save'),
];
}
public function save(): void
{
try {
$data = $this->form->getState();
User::where('id', auth()->user()->id)->update($data);
} catch (Halt $exception) {
return;
}
Notification::make()
->success()
->title(__('filament-panels::resources/pages/edit-record.notifications.saved.title'))
->send();
}
}