Using Laravel 6, I inject a model in a controller like this :
public function edit(School $school)
{
return view('/school/form', ['school' => $school]);
}
All is working fine when I enter an url like this :
http://localhost:8000/schools/3d537a0f-4c74-4fae-99af-6f1b2c4b34c8/edit
But if I try another url like this one (with a wrong uuid):
http://localhost:8000/schools/3d537a0f-4c74-4fae-99af-6f/edit
Then I have this PostgreSQL error :
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type uuid: "3d537a0f-4c74-4fae-99af-6f1b2c4b34c" (SQL: select * from "schools" where "id" = 3d537a0f-4c74-4fae-99af-6f1b2c4b34c limit 1)
Does it mean that I have to check the uuid before ? Is there any elegant way to prevent this and to have an automatic redirection to a 404 page ?