How much for two notebooks?
Pick a quantity and see the reply from the example route. No setup needed.
Check your work
Find the total for two notebooks in cents. Then leave the quantity out and identify which field Laravel asks for.
Build it locally
Laravel 13 · 18 minA route tells Laravel which code to run for a web address. Here, a GET request asks for a price. The reply is JSON, a format that pairs names such as total_cents with values such as 798.
Run it in your own Laravel app
Want to change the price yourself? With PHP and Composer installed, run the commands below in a terminal. The Laravel installation guide covers setup. Leave the server running and use the address Artisan prints.
composer create-project laravel/laravel request-lab '^13.0'
cd request-lab
php artisan serve
Connect input to a response
Append the route to routes/web.php. If the generated file already imports Route, keep a single import. This calculator only reads input. A GET request to it does not change any data.
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::get('/lab/estimate', function (Request $request) {
$data = $request->validate([
'units' => ['required', 'integer', 'between:1,50'],
]);
$units = (int) $data['units'];
return response()->json(['units' => $units, 'total_cents' => $units * 399]);
});
In a second terminal, send the following requests.
curl -i -H 'Accept: application/json' 'http://localhost:8000/lab/estimate?units=3'
curl -i -H 'Accept: application/json' 'http://localhost:8000/lab/estimate?units=51'
The first response should be 200 with {"units":3,"total_cents":1197}. The second should be 422 with an error under errors.units. The Accept header tells Laravel that this client expects JSON when validation fails.
Practice and verify
Run php artisan route:list --path=lab/estimate and confirm the GET route is registered. Send a request without a quantity, then one to /lab/not-found. Compare the validation error with the 404 from an unregistered route. Try a value of 1 and then 50 to verify the inclusive bounds. These are different failures, and each has a different fix.