當驗證失敗時,我對$errors變量一無所知,它曾經可以工作,但現在它停止了,我不知道為什么。我已經嘗試了幾件事,更改了失敗的字段,在請求的不同方法中添加了請求,我在請求中評論了不同的方法,但什么也沒有。我已經從我正在使用的中間件(查看作曲家中間件)中排除了該方法,什么也沒有。知道發生了什么嗎?一個重要的注意事項是創建視圖與版本相同。當它“創建”一個帖子時,點擊使用父請求 PostRequest 的 store 方法,并且一切正常,$errors 變量被填充。一些代碼。我的帖子路由文件:Route::resource('posts', 'PostController');RouteServiceProvider我清楚地包含web中間件的方法:protected function mapPostsRoutes(){ Route::middleware('web') ->namespace($this->namespace) ->group(base_path('routes/posts.php'));}我在更新方法中使用自定義表單請求的地方,PostController: /*** @param PostUpdateRequest $request* @param Post $post* @return Factory|RedirectResponse|View*/public function update(PostUpdateRequest $request, Post $post){// and so on 我的孩子PostUpdateRequest表格請求更新目的:<?phpnamespace App\Http\Requests;use Illuminate\Validation\Rule;class PostUpdateRequest extends PostRequest{ /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return array_merge( parent::rules(), [ 'slug' => [ 'required', 'string', Rule::unique('posts', 'slug')->ignore($this->slug, 'slug') ], ]); }}
FormRequest 不生成錯誤消息
慕桂英3389331
2022-07-22 19:23:52
