Skip to content

Commit 48e0564

Browse files
feat:[lar-102] add profil page in setting
1 parent 2c5cd7c commit 48e0564

File tree

28 files changed

+3880
-741
lines changed

28 files changed

+3880
-741
lines changed

app/Http/Controllers/User/SettingController.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,9 @@
66

77
use App\Events\EmailAddressWasChanged;
88
use App\Http\Controllers\Controller;
9-
use App\Http\Requests\UpdatePasswordRequest;
109
use App\Http\Requests\UpdateProfileRequest;
11-
use Illuminate\Contracts\View\View;
1210
use Illuminate\Http\RedirectResponse;
13-
use Illuminate\Support\Carbon;
1411
use Illuminate\Support\Facades\Auth;
15-
use Illuminate\Support\Facades\Cache;
16-
use Illuminate\Support\Facades\DB;
17-
use Illuminate\Support\Facades\Hash;
18-
use Jenssegers\Agent\Agent;
19-
use Stevebauman\Location\Facades\Location;
2012

2113
final class SettingController extends Controller
2214
{
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Livewire\Components\User;
6+
7+
use App\Events\EmailAddressWasChanged;
8+
use Filament\Forms\Components\FileUpload;
9+
use Filament\Forms\Components\Section;
10+
use Filament\Forms\Components\Textarea;
11+
use Filament\Forms\Components\TextInput;
12+
use Filament\Forms\Concerns\InteractsWithForms;
13+
use Filament\Forms\Contracts\HasForms;
14+
use Filament\Forms\Form;
15+
use Filament\Notifications\Notification;
16+
use Illuminate\Contracts\View\View;
17+
use Illuminate\Support\Facades\Auth;
18+
use Livewire\Component;
19+
use Ysfkaya\FilamentPhoneInput\Forms\PhoneInput;
20+
21+
/**
22+
* @property Form $form
23+
*/
24+
final class Profil extends Component implements HasForms
25+
{
26+
use InteractsWithForms;
27+
28+
public ?array $data = [];
29+
30+
public string $emailAddress = '';
31+
32+
public function mount(): void
33+
{
34+
$this->form->fill(Auth::user()->toArray()); // @phpstan-ignore-line
35+
$this->emailAddress = Auth::user()->email; // @phpstan-ignore-line
36+
}
37+
38+
public function form(Form $form): Form
39+
{
40+
return $form
41+
->schema([
42+
Section::make(__('pages/account.settings.profile_title'))
43+
->description(__('pages/account.settings.profile_description'))
44+
->schema([
45+
TextInput::make('username')
46+
->label(__('validation.attributes.username'))
47+
->prefix('laravel.cm/user/')
48+
->required(),
49+
Textarea::make('bio')
50+
->label(__('validation.attributes.bio'))
51+
->rows(4)
52+
->cols(20)
53+
->helperText(__('pages/account.settings.bio_description')),
54+
FileUpload::make('avatar')
55+
->label(__('validation.attributes.avatar'))
56+
->helperText(__('pages/account.settings.avatar_description'))
57+
->image()
58+
->maxSize(1024),
59+
TextInput::make('website')
60+
->label(__('validation.attributes.website'))
61+
->placeholder('https://www.example.com')
62+
->url(),
63+
]),
64+
65+
Section::make(__('pages/account.settings.personal_information_title'))
66+
->description(__('pages/account.settings.personal_information_description'))
67+
->schema([
68+
TextInput::make('name')
69+
->label(__('validation.attributes.last_name'))
70+
->required(),
71+
TextInput::make('email')
72+
->label(__('validation.attributes.email'))
73+
->email()
74+
->suffixIcon(fn () => (Auth::user()?->hasVerifiedEmail() ? 'heroicon-m-check-circle' : 'heroicon-m-exclamation-triangle'))
75+
->suffixIconColor(fn () => (Auth::user()?->hasVerifiedEmail()) ? 'success' : 'warning')
76+
->HelperText(fn () => (! Auth::user()?->hasVerifiedEmail()) ? __('pages/account.settings.unverified_mail')
77+
: '')
78+
->required(),
79+
TextInput::make('location')
80+
->label(__('validation.attributes.location')),
81+
PhoneInput::make('phone_number')
82+
->label(__('validation.attributes.phone')),
83+
]),
84+
85+
Section::make(__('pages/account.settings.social_network_title'))
86+
->description(__('pages/account.settings.social_network_description'))
87+
->schema([
88+
TextInput::make('twitter_profile')
89+
->label(__('Twitter'))
90+
->helperText(__('pages/account.settings.twitter_helper_text'))
91+
->prefix('twitter.com/'),
92+
TextInput::make('github_profile')
93+
->label(__('GitHub'))
94+
->prefix('github.com/'),
95+
TextInput::make('linkedin_profile')
96+
->label(__('LinkedIn'))
97+
->prefix('linkedin.com/in/'),
98+
]),
99+
])
100+
->statePath('data')
101+
->model(Auth::user());
102+
}
103+
104+
public function updateProfil(): void
105+
{
106+
$this->validate();
107+
Auth::user()->update($this->form->getState()); // @phpstan-ignore-line
108+
$user = Auth::user()->refresh(); // @phpstan-ignore-line
109+
if ($user->email !== $this->emailAddress) {
110+
$user->email_verified_at = null;
111+
$user->save();
112+
113+
event(new EmailAddressWasChanged($user));
114+
}
115+
116+
Notification::make()
117+
->success()
118+
->title(__('notifications.user.profile_updated'))
119+
->duration(3500)
120+
->send();
121+
}
122+
123+
public function render(): View
124+
{
125+
return view('livewire.components.user.profil');
126+
}
127+
}

app/Providers/AppServiceProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Filament\Tables;
2020
use Illuminate\Database\Eloquent\Relations\Relation;
2121
use Illuminate\Support\Facades\Blade;
22-
use Illuminate\Support\Facades\Route;
2322
use Illuminate\Support\Facades\View;
2423
use Illuminate\Support\ServiceProvider;
2524
use Illuminate\Support\Str;

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"torchlight/torchlight-laravel": "^0.6",
4949
"wire-elements/modal": "^2.0",
5050
"wire-elements/spotlight": "^2.0",
51-
"yarri/link-finder": "^2.7.10"
51+
"yarri/link-finder": "^2.7.10",
52+
"ysfkaya/filament-phone-input": "^3.1"
5253
},
5354
"require-dev": {
5455
"fakerphp/faker": "^1.23.0",

0 commit comments

Comments
 (0)