71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Account;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\EditProfilePostRequest;
|
|
use App\Models\File;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class EditProfileController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$user = auth()->user();
|
|
|
|
return view('account.setting', compact('user'));
|
|
|
|
}
|
|
|
|
public function post(EditProfilePostRequest $request)
|
|
{
|
|
$user = auth()->user();
|
|
|
|
$inputs = $request->only([
|
|
'first_name',
|
|
'last_name',
|
|
'mobile',
|
|
'email',
|
|
'province_id',
|
|
'city_id',
|
|
]);
|
|
|
|
if ($request->hasFile('image')) {
|
|
|
|
$image = $request->file('image');
|
|
|
|
$imageName = time() . rand(11111, 99999) . '.' . $image->extension();
|
|
|
|
$path = $image->storeAs(
|
|
'user_images',
|
|
$imageName,
|
|
'public'
|
|
);
|
|
|
|
$file = File::create([
|
|
'name' => $imageName,
|
|
'size' => $image->getSize(),
|
|
'original_name' => $image->getClientOriginalName(),
|
|
'path' => $path,
|
|
'extension' => $image->extension(),
|
|
]);
|
|
|
|
$inputs['image_id'] = $file->id;
|
|
}
|
|
|
|
if ($request->filled('new_password')) {
|
|
$inputs['password'] = Hash::make(
|
|
$request->input('new_password')
|
|
);
|
|
}
|
|
|
|
$user->update($inputs);
|
|
|
|
return redirect()
|
|
->back()
|
|
->with('success', 'پروفایل با موفقیت بروزرسانی شد.');
|
|
}
|
|
|
|
}
|