如果请求是获取而不是发布,如何返回?

问题描述 投票:0回答:1

我有一条提交表单的路线。这条路线是邮政类型。当我将该网址直接放在浏览器的地址栏中时,会出现此错误。

此路由不支持GET方法。支持的方法:POST。

我想要的是,它应该返回而不是给出错误。

路线:

Route::post('/warehouse-locations-import', 'WarehouseLocationController@warehouseLocationsImport')
        ->name('warehouselocations.import');

控制器:

//this function will extract all locations data from file
public function extractWarehouseLocations($locations)
{
    if ($locations['E'] && $locations['L'] && $locations['B'] && $locations['K']) {
        //making array of location data
        $locationArray = array(
            'name' => $locations['B'],
            'barcode' => $locations['C'],
            'group' => $locations['D'],
            'capacity' => $locations['E'],
            'row' => $locations['F'],
            'bay' => $locations['G'],
            'level' => $locations['H'],
            'depth' => $locations['I'],
            'product_type' => $locations['J'],
            'pick_efficiency' => $locations['K']
        );

        //adding index in array according to if condition
        $locations['L'] ? $locationArray['status'] = 1 : $locationArray['status'] = 0;
    }
}
laravel laravel-5 post get routes
1个回答
0
投票

您可以通过使用get方法和post方法来显示您可以使用的方法发送尝试,

Route::post('/warehouse-locations-import','WarehouseLocationController@warehouseLocationsImport')
            ->name('warehouselocations.import');
Route::get('/warehouse-locations-import', 'WarehouseLocationController@warehouseLocationsImportForm')
            ->name('warehouselocations.importform');
© www.soinside.com 2019 - 2024. All rights reserved.