Getting 404 not found Laravel POST request

Viewed 9837

I am making a post request in my form

 <form action="/confirmation" method="POST"> 
      {{ csrf_field() }}
      <input type="text" name="confirmationcode" required>
      <button type="submit">Submit</button>
 </form>

My route

Route::post('/confirmation', 'bookController@confirmation');

My bookController

public function confirmation() 
{
    $code = request('confirmationcode');
    dd($code);
}

I am getting 404 in my console

POST http://127.0.0.8000/confirmation 404 (Not Found)

And Sorry, the page you are looking for could not be found. in my browser

I just cannot seem to figure out what is wrong, I wonder if another pair of eyes can help me.

4 Answers

The same thing happened to me, everything was ok, I tried to refresh the cache and it worked, you can try the following commands in the terminal

php artisan optimize
php artisan route:cache
php artisan view:clear
php artisan config:cache

Try this

public function confirmation(Request $request) 
{
    $code = $request->confirmationcode;
    dd($code);
}

Make sure the $code is set

Try this on your controller

public function confirmation()
{
    if(isset($code))
    {
    $code = request('confirmationcode');
    dd($code)
    }
    dd('fail');
}

If the $code is set then only try to dd($code) if that does not work try if(!empty($code))

Try to use the url() helper function

<form action="{{url('confirmation')}}" method="POST">
Related