Route [calculator] not defined. Laravel 5.6

0

Good morning!

I am developing a small application that contains a sales margin calculator. This calculator I have it at the first sight, and calls a form that sends to the controller of the home in laravel. For some reason, mark that I do not have the path defined when I have defined it in the web.php file and as much as I change the name, it does not work. I have tried to generate a controller exclusively for the calculator and change the path to point to that controller, but it still does not work. This happens to me in the main server, because I have another development server where the route with that same function works without problem. I attach the code of my view, controller and file of routes.

View of the home:

<div class="col-sm-8">
    <div class="card" style="margin-top: 15px">
      <div class="card-header">
        <h5 style="margin-top:5px">Calculadora márgenes de venta</h5>
      </div>
      <div class="card-body">
        <form action="{{route('calculator')}}" method="POST" autocomplete="off">
          @csrf
          <div class="row">
            <div class="col-sm-8">
              <input type="text" class="form-control" name="number" value="{{Session::get('calculator')}}">
            </div>
            <div class="col-sm-2">
              <input type="number" class="form-control" step="0.0001" name="divider">
            </div>
            <div class="col-sm-2">
              <input type="submit" value="Calcular" class="btn btn-secondary">
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>

web.php routes file:

Auth::routes();
Route::get('home', 'HomeController@index')->name('home');
Route::post('home', 'HomeController@calculator')->name('calculator');

function in the HomeController controller:

public function calculator(Request $request){
  $request->validate([
    'number' => 'required|numeric',
    'divider' => 'required|numeric',
  ]);

  $calculator = round($request['number'] / ((100 - $request['divider']) / 100), 4);
  return redirect()->back()->with('calculator', $calculator);
}

I use laravel 5.6. I do not know where I'm failing, I hope you can help me. Thanks in advance!

    
asked by Ferran Herrero Soto 27.08.2018 в 09:43
source

1 answer

0

I've already managed to fix the problem. Everything came because in the input I put a submit type, so I changed it to the following code:

<div class="col-sm-1">
  <button type="submit" class="btn btn-primary" style="padding-top: 10px; padding-bottom: 10px;">
    <i class="fas fa-calculator"></i>
 </button>
</div>

With this the request was sent to the corresponding route. Perhaps not using a button as such did not apply the POST method. It seems strange to me, because I understood that it was not necessary to use the button if your input was of the submit type, and it was broken to see that in the other test server it worked correctly.

I hope this can help someone in the future. Thanks to the community for trying to help me!

    
answered by 27.08.2018 в 16:44