AccountController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Http\Controllers\Panel\Account;
  3. use App\Http\Controllers\Controller;
  4. use App\User;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Validation\Rule;
  8. class AccountController extends Controller
  9. {
  10. public function edit(User $account)
  11. {
  12. return view('panel.account.edit', compact('account'));
  13. }
  14. public function update(Request $request, User $account)
  15. {
  16. $data = $request->validate([
  17. 'name' => ['required', 'string', 'max:255'],
  18. 'username' => ['required', 'string', 'max:255', Rule::unique('users')->ignore($account->id)],
  19. 'mobile' => ['required', 'regex:/^09\d{9}$/', 'digits:11', 'numeric'],
  20. 'email' => ['required', 'string', 'email', 'max:255'],
  21. 'two_factor_status' => ['required', 'in:off,sms,email'],
  22. ]);
  23. DB::beginTransaction();
  24. try {
  25. $account->update($data);
  26. DB::commit();
  27. alert()->success('با موفقیت بروزرسانی شد.')->persistent('باشه');
  28. } catch (\Exception $e) {
  29. DB::rollBack();
  30. alert()->warning('بروزرسانی با خطا مواجه شد.')->persistent('باشه');
  31. }
  32. return back();
  33. }
  34. }