feat: add profile editing
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Account;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\EditProfilePostRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class EditProfileController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
return view('account.edit-profile.index', compact('user'));
|
||||
}
|
||||
|
||||
public function post(EditProfilePostRequest $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$user->name = $request['name'];
|
||||
$user->username = $request['username'];
|
||||
$user->email = $request['email'];
|
||||
|
||||
if ($request->filled('password')) {
|
||||
$user->password = Hash::make($request['password']);
|
||||
}
|
||||
|
||||
$user->save();
|
||||
|
||||
return redirect()
|
||||
->route('account.edit-profile.index')
|
||||
->with('success', 'اطلاعات پروفایل با موفقیت ویرایش شد.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class EditProfilePostRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
|
||||
'name' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
'username' =>
|
||||
[
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
'unique:users,username,' . $user->id,
|
||||
],
|
||||
'email' => [
|
||||
'required',
|
||||
'email',
|
||||
'max:255',
|
||||
'unique:users,email,' . $user->id,
|
||||
],
|
||||
'password' =>
|
||||
|
||||
[
|
||||
'nullable',
|
||||
'string',
|
||||
'min:8',
|
||||
'confirmed'
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user