Try applying regex to the route
Route::get('api/users/{user}', function (App\User $user) {
return $user->email;
})->where('user', '[0-9]+');;
https://laravel.com/docs/5.7/routing#parameters-regular-expression-constraints
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have one issue with Laravel Spark 7.0, the route model binding doesn't abort when it passes a string. It works fine at Laravel 5.7, only in Spark it happens.
Any one can help me with this? Thanks.
Route
Route::get('api/users/{user}', function (App\User $user) {
return $user->email;
});
Example: app.local/api/user/test
Result
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "test" (SQL: select * from "users" where "id" = test limit 1)
If you scroll down to the next section in the docs, you can set them globally so it's not tied to a specific route.
public function boot()
{
Route::pattern('user', '[0-9]+');
parent::boot();
}
Please or to participate in this conversation.