d43e74b280
git commit "add profile image upload support"
57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\ProfileUpdateRequest;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class ProfileController extends Controller
|
|
{
|
|
public function edite()
|
|
{
|
|
$withoutHero=true;
|
|
$user=Auth::User();
|
|
return view('users.profile.edit',compact('user','withoutHero'));
|
|
}
|
|
|
|
public function update(ProfileUpdateRequest $request)
|
|
{
|
|
$user=$request->user();
|
|
$inputs=$request->validated();
|
|
|
|
if (!empty($inputs['new_password'])){
|
|
$user->password=Hash::make($inputs['new_password']);
|
|
}
|
|
|
|
unset(
|
|
$inputs['current_password'],
|
|
$inputs['new_password'],
|
|
$inputs['new_password_confirmation'],
|
|
|
|
);
|
|
|
|
if ($request->hasFile('profile_image')) {
|
|
|
|
$image = $request->file('profile_image');
|
|
|
|
$imageName = time() . '.' . $image->getClientOriginalExtension();
|
|
|
|
$image->move(
|
|
public_path('uploads/users'),
|
|
$imageName
|
|
);
|
|
|
|
$inputs['profile_image'] = $imageName;
|
|
}
|
|
$user->update($inputs);
|
|
|
|
return back()->with([
|
|
'success','اطلاعات کاربر با موفقیت ویرایش شد.'
|
|
]);
|
|
|
|
}
|
|
}
|