Laravel 4: Verify if a route exists or not

Aren’t those error pages ugly when you try to link to a route that doesn’t exist?

We can check if a route exists or not, with:

@if(Route::getRoutes()->hasNamedRoute('route.name'))
  {{ link_to_route('route.name') }}
@endif

Or, if you like it more in php…

<?php
if(Route::getRoutes()->hasNamedRoute('route.name'))
{
  echo link_to_route('route.name');
}
?>

It will return true/false. Thank you, carbontwelve.

2 comments

    1. Wow… Nice. Could you tell me what you love about Laravel? Besides the huge number of files it loads for a simple page…

Leave a Reply

Your email address will not be published. Required fields are marked *

No spam? * Time limit is exhausted. Please reload CAPTCHA.