I am making a simple form two sum two values. I want to display the calculated result in an readonly input after the request went through. If I dd() the sum of my two fields, the sum is correct. But I am unable to pass the sum back to the view.
I searched around the web and found nothing promising. Same with the Laravel documentation.
Form:
<p>
<input type="number" name="numberOne" value="{{ old('numberOne') }}">
</p>
<p>
<input type="number" name="numberTwo" value="{{ old('numberTwo')}}">
</p>
<p>
<input type="number" name="calculated" value="{{ isset($calculated) ? $calculated : '' }}" readonly>
</p>
Controller:
class CalculationsController extends Controller
{
public function process(Request $request) {
$numberOne = $request->input('numberOne');
$numberTwo = $request->input('numberTwo');
$calculated = $numberOne + $numberTwo;
dd($calculated);
return redirect('/')->withInput();
}
}
Expected would be the sum of both inputs in the readonly. But after the submit, it's still empty. What am I doing wrong?