Skip to content

Incorrect Route Binding Does Not Return 404 HTTP Status #2010

@Sam7367238

Description

@Sam7367238

Tempest version

3.0

PHP version

8.5

Operating system

Windows

Description

In here, I have a Post model.

namespace App\Model;

use Tempest\Database\PrimaryKey;
use Tempest\Router\Bindable;
use function Tempest\Database\query;

final class Post implements Bindable
{
    public PrimaryKey $id;

    public function __construct(
        public string $title,
        public string $content
    ) {
    }

    public static function resolve(string $input): Bindable
    {
        return query(self::class)->resolve($input);
    }
}

I am following the documentation on route binding. And in my controller, I have this show action:

#[Get("/posts/{post}")]
    public function show(Post $post)
    {
        return view(root_path("resources/templates/posts/show.view.php"), post: $post);
    }

When I visit this route with an existing post (localhost/posts/1), I get the expected response of a view along with the post's data. However, if I visit the same route with a post ID that doesn't exist, I get an error with the HTTP 500 status, this might be a bug and it would be better if a 404 status is returned.

Image

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions