Skip to content
Advertisement

Laravel 5.8: POST Route Does Not Seem To Be Working

I’m using Laravel 5.8 for my project and in this project, I have added this route:

Route::post('course_admin/{id}','CourseController@AcceptWalletCourse')->name('accept.walletCourse');

And here is the form:

<form method="POST" action="{{ route('accept.walletCourse',['id'=>last(request()->segments())]) }}">
   @csrf

   Are you sure?

   <button type="submit" class="btn btn-success">Yes</button>
</form>

And at the Controller, I added this:

dd($request);

But I don’t know why nothing appears as result. I mean the page just refreshes without showing any error or any dd result.

So what’s going wrong here? How can I solve this issue?

Advertisement

Answer

Try to simplify everything:

<form method="POST" action="{{ route('accept.walletCourse',['id'=> 12]) }}">
   @csrf

   Are you sure?

   <button type="submit" class="btn btn-success">Yes</button>
</form>

In your controller:

public function AcceptWalletCourse($id)
{
    dd($id); //should print 12
}

Once you are at this point, you can start adding validations, policies or dynamic parameters in your form (for instance last(request()->segments())) .

By proceeding step by step, you will quickly find where is the problem.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement