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

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


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


You can also use Route::current()->getName() to check your route name.

Example: routes.php

Route::get('test', ['as'=>'testing', function() {    return View::make('test');}]);

View:

@if(Route::current()->getName() == 'testing')    Hello This is testing@endif


Maybe you should try this:

<li class="{{ Request::is('admin/dashboard') ? 'active' : '' }}">Dashboard</li>