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

socieboy's avatar

Route name exists?

Hey guys what's the best method to know if a route name exists.

something like.

if(Route::exists('name.of.my.route'))
{
    //Route exists
}else{
    //Register route.
}
0 likes
5 replies
RachidLaasri's avatar
Level 41

Better post the answer for others coming from Google.

 if( Route::has('posts.create') )
 {
    return true;
 }
 return false;
8 likes
mstnorris's avatar

@socieboy a better reply than "Thank you guys! I already figure out!" would be to say what you did, as @RachidLaasri says, if people find this thread through Google or whatever, later down the line, it is better to be informative than just to say "I've done it.".

2 likes
JonStewart's avatar

Answer seems to be out of date for Laravel 7, as Route::has does not appear to exists anymore?

Can anybody suggest where it has moved or the alternative is hiding? Google is not being my friend!

Please or to participate in this conversation.