dimanche 5 avril 2020

How to return back if request is get instead of post?

I have a route on which I submit a form. This route is Post type. when I directly put that url in address bar of browser it give me this error.

The GET method is not supported for this route. Supported methods: POST.

what I want is, it should return back instead of giving error.

Route:

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

Controller:

//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;
    }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire