app/Http/Requests/UserRequest.php
/**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
Get the validation rules that apply to the request.
@return array
Get the validation rules that apply to the request . @return array
public function rules()
    {
        if ($this->route()->getName() == 'user.update') {
            $id = request()->segment(2);
            return [
                'name' => 'required',
                'email' => 'nullable|email|unique:users,email,' . $id . ',id',
                'password' => 'nullable|confirmed|min:8|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/',
                'password_confirmation' => 'nullable',
                'role_id' => 'required|integer|not_in:0',
                'is_active' => 'required|in:0,1',
            ];
        }
        return [
            'name' => 'required',
            'email' => 'required|email|unique:users,email',
            'password' => 'required|confirmed|min:8|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/',
            'password_confirmation' => 'required',
            'role_id' => 'required|integer|not_in:0',
            'is_active' => 'required|in:0,1',
        ];
    }
public function rules ( ) { if ( $ this -> route ( ) -> getName ( ) == 'user.update' ) { $ id = request ( ) -> segment ( 2 ) ; return [ 'name' => 'required' , 'email' => 'nullable|email|unique:users,email,' . $ id . ',id' , 'password' => 'nullable|confirmed|min:8|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/' , 'password_confirmation' => 'nullable' , 'role_id' => 'required|integer|not_in:0' , 'is_active' => 'required|in:0,1' , ] ; } return [ 'name' => 'required' , 'email' => 'required|email|unique:users,email' , 'password' => 'required|confirmed|min:8|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/' , 'password_confirmation' => 'required' , 'role_id' => 'required|integer|not_in:0' , 'is_active' => 'required|in:0,1' , ] ; }
Get the validation rules that apply to the request.
Get the validation rules that apply to the request .