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!