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

前端 未结 28 2474
眼角桃花
眼角桃花 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:35

    To get current url in blade view you can use following,

    <a href="{{url()->current()}}">Current Url</a>
    

    So as you can compare using following code,

    @if (url()->current() == 'you url')
        //stuff you want to perform
    @endif
    
    0 讨论(0)
  • 2020-11-28 01:35

    Try this:

    @if(collect(explode('/',\Illuminate\Http\Request::capture()->url()))->last() === 'yourURL')
        <li class="pull-right"><a class="intermitente"><i class="glyphicon glyphicon-alert"></i></a></li>
    @endif
    
    0 讨论(0)
  • 2020-11-28 01:35

    Try this way :

    <a href="{{ URL::to('/registration') }}">registration </a>
    
    0 讨论(0)
  • 2020-11-28 01:36

    You should try this:

    <b class="{{ Request::is('admin/login') ? 'active' : '' }}">Login Account Details</b>
    
    0 讨论(0)
  • 2020-11-28 01:37

    In Blade file

    @if (Request::is('companies'))
       Companies name 
    @endif
    
    0 讨论(0)
  • 2020-11-28 01:39

    You can use this code to get current URL:

    echo url()->current();
    
    echo url()->full();
    

    I get this from Laravel documents.

    0 讨论(0)
提交回复
热议问题