php artisan make:class Services/Calculator
app/Services/Calculator.php
<?php
namespace App\Services;
class Calculator
{
public function add(array $numbers): int
{
return array_sum($numbers);
}
}
routes/web.php
<?php
use App\Services\Calculator;
use Illuminate\Support\Facades\Route;
Route::get('/', function (Calculator $calculator) {
return $calculator->add(range(1, 100));
});