Laravel – How to Get the Current URL Inside @if Statement (Blade) in Laravel 4

laravellaravel-4laravel-blade

I am using Laravel 4. I would like to access the current URL inside an @if condition in a view using the Laravel's Blade templating engine but I don't know how to do it.

I know that it can be done using something like <?php echo URL::current(); ?> but It's not possible inside an @if blade statement.

Any suggestions?

Best Answer

You can use: Request::url() to obtain the current URL, here is an example:

@if(Request::url() === 'your url here')
    // code
@endif

Laravel offers a method to find out, whether the URL matches a pattern or not

if (Request::is('admin/*'))
{
    // code
}

Check the related documentation to obtain different request information: http://laravel.com/docs/requests#request-information