Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hjortur17's avatar

404 error even tho the route exist

Hi, I can't figure out why my route is not working. I always get 404 error when trying to access it, I have tried php artisan route:clear, php artisan optimize:clear and php artisan cache:clear but nothing changes.

Here is the route I'm trying to visit (I can see the route when I run php artisan route:list)

Route::get('/test/mail', function () {
    $booking = Rental::where('id', 3)->with([
        'car',
        'customer',
        'drivers',
        'price',
        'packages',
        'insurances',
        'extras'
    ])->firstOrFail();

    Mail::to($booking->customer->email_address)->send(new BookingConfirmed($booking));

    return "Hallo world";
});
0 likes
2 replies
tykus's avatar

Is it possible that a different Route is being matched? What does the full routes file look like?

1 like
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Most likely you dont have a Rental with id 3.

Change firstOrFail to first and dd($booking). If its null, there is no such rental. If you are 100% sure there is one in the database, you might have a global scope set on the Rental model

1 like

Please or to participate in this conversation.