Maruf Hosen
Maruf Hosen

Reputation: 3

For a form the GET method is not supported for this route

I have set the POST method for inserting data in a form. I have set the POST method in web.php also. But whenever I want to insert data through form it shows that Get method is not supported. But I have write the POST method in both form and route. Here is my code:

Form:

<form action="{{url('/admin/prescription/store')}}" method="POST"> 
@csrf

Route::post('/admin/prescription/store','prescriptionController@store')->name('prescription.store');

Controller:

public function store(Request $request)
{
    $prescription = new Prescription();
    $prescription->full_name = $request->full_name;
    $prescription->nid = $request->nid;
    $prescription->address = $request->address;
    $prescription->contactNum = $request->contactNum;
    $prescription->health_cond = $request->health_cond;
    $prescription->desc = $request->desc;
    $prescription->save();
     
    return redirect()
        ->route('prescription.store')
        ->with('success','Prescription added Successfully.');
 }

Upvotes: 0

Views: 65

Answers (3)

Naime
Naime

Reputation: 74

It's because of your redirect in store(), you should redirect to a get Route

Upvotes: 1

Bennett
Bennett

Reputation: 738

To use one route for both types of requests, you could do:

Route::match(['GET', 'POST'],'/admin/prescription/store', 'ExampleController@store');

Upvotes: 1

Flo Espen
Flo Espen

Reputation: 469

This is because of your redirect to a post Route. Redirect works as get request.

Upvotes: 3

Related Questions