Laravel:Method ...控制器::显示不存在

Laravel:Method ...Controller::show does not exist

我正在尝试验证 post 请求。我想当验证失败时,它会给我这个错误信息。

app/Http/Controllers/InternationalShippingController.php

public function store(Request $request){
    //echo '<pre>';
    $post = $request->post();
    $order_ids = session('international_order_ids');
    //var_dump($order_ids);
    //var_dump($post);

    $validator = Validator::make(
      $post,[
          'documents.*' => 'mimes:jpg,jpeg,png,pdf|max:5000|nullable',
          'company_name' => 'nullable',
          'shipping_address1' => 'nullable',
          'message' => 'size:1000',
        ],[
            'image_file.*.mimes' => __('Only jpeg,png and pdf files are allowed'),
            'image_file.*.max' => __('Sorry! Maximum allowed size for an document is 5MB'),
        ]
    );

    if($validator->fails()){
        return redirect('internationalshippings/create2')
            ->withErrors($validator)
            ->withInput();
    }
}

web.php

Route::post('internationalshippings/create2','InternationalShippingController@create2');
Route::resource('internationalshippings','InternationalShippingController');

我还没有在控制器中创建 show() 方法。 这个错误是否意味着当验证失败时,它会尝试重定向到 internationalshippings/show 方法? 当验证失败时,我希望它重定向回 internationalshippings/create2。我怎样才能做到这一点?

谢谢

您正在使用 resource 控制器, 在 resources 中,此 url internationalshippings/SomeThing 表示 show 方法 我的意思是此 url 调用资源中的 show 方法

第一种方式
所以你可以在失败时使用它 return:
return redirect()->route('your_route_name')return back()

第二种方式
第二种方式是在你的 web.php 中,当你定义资源路由时,这样输入:
Route::resource('internationalshippings','InternationalShippingController',['except'=>['show']]);


编辑:
在您的代码情况下,最好的方法是更改​​ Return,因为您要重定向到它的 url 是 POST