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;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化