fix : update user profile edit in user side
This commit is contained in:
@@ -3,14 +3,70 @@
|
||||
namespace App\Http\Controllers\Account;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\File;
|
||||
use Illuminate\Http\Request;
|
||||
use function Symfony\Component\String\s;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
//
|
||||
public function index()
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
return view('account.profile', compact('user'));
|
||||
}
|
||||
|
||||
public function updateImage(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'image' => [
|
||||
'required',
|
||||
'image',
|
||||
'mimes:jpg,jpeg,png,webp',
|
||||
'max:2048',
|
||||
],
|
||||
]);
|
||||
|
||||
$user = auth()->user();
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
|
||||
$image = $request->file('image');
|
||||
|
||||
$extension = $image->extension();
|
||||
|
||||
$imageName = $user->id . '_' . rand(11111, 99999) . '_' . time() . '.' . $extension;
|
||||
|
||||
$path = $image->storeAs('user_profile', $imageName, 'public'
|
||||
);
|
||||
|
||||
if ($user->file) {
|
||||
|
||||
$user->file->update([
|
||||
'name' => $imageName,
|
||||
'original_name' => $image->getClientOriginalName(),
|
||||
'path' => $path,
|
||||
'extension' => $extension,
|
||||
'size' => $image->getSize(),
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
$file = File::create([
|
||||
'name' => $imageName,
|
||||
'original_name' => $image->getClientOriginalName(),
|
||||
'path' => $path,
|
||||
'extension' => $extension,
|
||||
'size' => $image->getSize(),
|
||||
]);
|
||||
|
||||
$user->update([
|
||||
'file_id' => $file->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return back()->with('success', 'عکس پروفایل با موفقیت تغییر کرد.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,4 +33,6 @@ class DashboardController extends Controller
|
||||
return view('admin.dashboard', compact('flightsCount', 'usersCount',
|
||||
'bookingsCount', 'indexPageCont' , 'visits'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,24 @@
|
||||
<img src="{{ asset('assets/img/account/user.jpg') }}" alt="">
|
||||
@endif
|
||||
<button type="button" class="profile-img-btn"><i class="far fa-camera"></i></button>
|
||||
<input type="file" class="profile-img-file">
|
||||
<form
|
||||
action="{{ route('account.profile.image.update') }}"
|
||||
method="POST"
|
||||
enctype="multipart/form-data"
|
||||
id="profile-image-form"
|
||||
>
|
||||
@csrf
|
||||
|
||||
<input
|
||||
type="file"
|
||||
name="image"
|
||||
class="profile-img-file"
|
||||
id="profile-img-file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
hidden
|
||||
>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<h4>{{ getUserFullName() }}</h4>
|
||||
|
||||
@@ -21,3 +38,29 @@
|
||||
<li><a class="{{ activeAccountSidebar('auth.logout') }}" href="{{route('auth.logout')}}"><i class="far fa-sign-out"></i> خروج</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
const button = document.querySelector('.profile-img-btn');
|
||||
const fileInput = document.querySelector('#profile-img-file');
|
||||
const form = document.querySelector('#profile-image-form');
|
||||
|
||||
if (button && fileInput && form) {
|
||||
|
||||
button.addEventListener('click', function () {
|
||||
fileInput.click();
|
||||
});
|
||||
|
||||
fileInput.addEventListener('change', function () {
|
||||
|
||||
if (this.files.length > 0) {
|
||||
form.submit();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -107,6 +107,28 @@
|
||||
|
||||
</div>
|
||||
|
||||
<p class="flight-type">
|
||||
<i class="far fa-plane"></i>
|
||||
|
||||
@switch($flight->flight_type)
|
||||
|
||||
@case(0)
|
||||
رفت
|
||||
@break
|
||||
|
||||
@case(1)
|
||||
برگشت
|
||||
@break
|
||||
|
||||
@case(2)
|
||||
رفت و برگشت
|
||||
@break
|
||||
|
||||
@default
|
||||
-
|
||||
@endswitch
|
||||
</p>
|
||||
|
||||
<p class="flight-date">
|
||||
<i class="far fa-calendar-days"></i>
|
||||
{{ $flight->departure_time->toJalali()->format('Y/m/d H:i') }}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<input
|
||||
type="text"
|
||||
name="journey-date"
|
||||
class="form-control date-picker journey-date"
|
||||
class="form-control journey-date"
|
||||
value="{{ $item->departure_time->toJalali()->format('Y/m/d') }}"
|
||||
readonly
|
||||
>
|
||||
|
||||
@@ -35,6 +35,8 @@ Route::prefix('account')->name('account.')->middleware('auth')->group(function (
|
||||
|
||||
Route::get('profile', [ProfileController::class, 'index'])->name('profile');
|
||||
|
||||
Route::post('profile/image', [ProfileController::class, 'updateImage']) ->name('profile.image.update');
|
||||
|
||||
Route::prefix('edit-profile')->name('edit-profile.')->controller(EditProfileController::class)->group(function () {
|
||||
|
||||
Route::get('/', 'index')->name('index');
|
||||
|
||||
Reference in New Issue
Block a user