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

前端 未结 28 2621
眼角桃花
眼角桃花 2020-11-28 01:15

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 ho

28条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 01:20

    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
    

提交回复
热议问题