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

Developer654079525's avatar

Accessing route names before assigning them

I am trying to pass the canonical data and want to stick with named routes. Is it safe to use the route name in the Route::some_request before it was assigned?

Route::get('/', function () {
    // ...
    $canonical = route('home');
    return view('post', [
        'post' => $post,
        'canonical' => $canonical,
    ]);
})->name('home'); // named route

This seems to be working, but not sure if it is a good practice.

0 likes
1 reply

Please or to participate in this conversation.