修改用戶信息時,在表單請求驗證中排除當前郵箱所在的記錄行,並檢查郵箱的惟一性。php
5.2git
backend/user/{user}github
<?php namespace App\Http\Requests\Backend\User; use App\Http\Requests\Request; class UpdateRequest extends Request { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $id = $this->route('user'); //獲取當前須要排除的id return [ 'email' => "required|email|unique:users,email,".$id, ]; } }
unique:表名,字段,須要排除的IDapp
歡迎加入技術討論羣 QQ : 339803849
個人開源博客 : https://github.com/moell-peng...ui