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

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

    You will get the url by using the below code.

    For Example your URL like https//www.example.com/testurl?test

    echo url()->current();
    Result : https//www.example.com/testurl
    
    echo url()->full();
    Result: https//www.example.com/testurl?test
    
    0 讨论(0)
  • 2020-11-28 01:18
    @if(request()->path()=='/path/another_path/*')
    @endif
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-11-28 01:21

    Maybe you should try this:

    <li class="{{ Request::is('admin/dashboard') ? 'active' : '' }}">Dashboard</li>
    
    0 讨论(0)
  • 2020-11-28 01:21
    class="nav-link {{ \Route::current()->getName() == 'panel' ? 'active' : ''}}"
    
    0 讨论(0)
  • 2020-11-28 01:21

    Try This:

    <li class="{{ Request::is('Dashboard') ? 'active' : '' }}">
        <a href="{{ url('/Dashboard') }}">
    	<i class="fa fa-dashboard"></i> <span>Dashboard</span>
        </a>
    </li>

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