dongyi7901 2019-06-07 00:52
浏览 42
已采纳

申请表重定向到禁止页面

I followed laravel documentation about Form Request Validation. and im not sure if get it correctly. i created a make:request EmployeeRequest to validate an employee form. but for some reasons it only redirects me to a blank page with "forbidden" as message

// this is my request code
public function rules()
{
    return [
        'email' => 'bail|required|email|unique:employees|max:255',
        'first_name' => 'bail|required|max:50|min:2',
        'last_name' => 'bail|required|max:50|min:2',
        'date_of_birth' => 'bail|required',
        'contact_number' => 'bail|required|max:11',
        'image' => 'bail|required|image',
    ];
}

//then i called it in my controller like this
public function store(EmployeeRequest $request)
{
      //my code if everything is valid
}

(when entering invalid data) it only redirects me to a blank page with an echo of forbidden. im not sure if i understand it correctly. but im expecting that it will automatically redirects to the previous page with errors

  • 写回答

1条回答 默认 最新

  • dri8163 2019-06-07 01:00
    关注

    Maybe you have to authorize the user, or change the authorize() function to return true . From the docs:

    If the authorize method returns false, a HTTP response with a 403 status code will automatically be returned and your controller method will not execute.

    If you plan to have authorization logic in another part of your application, return true from the authorize method:

        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
        public function authorize()
        {
            return true;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?