Lumen: get URL parameter in a Blade view

前端 未结 10 1999
深忆病人
深忆病人 2020-12-13 03:20

I\'m trying to get a url parameter from a view file.

I have this url:

http://locahost:8000/example?a=10

and a view file na

相关标签:
10条回答
  • 2020-12-13 04:00

    if you use route and pass paramater use this code in your blade file

    {{dd(request()->route()->parameters)}}
    
    0 讨论(0)
  • 2020-12-13 04:06

    Given your URL:

    http://locahost:8000/example?a=10
    

    The best way that I have found to get the value for 'a' and display it on the page is to use the following:

    {{ request()->get('a') }}
    

    However, if you want to use it within an if statement, you could use:

    @if( request()->get('a') )
        <script>console.log('hello')</script>
    @endif
    

    Hope that helps someone! :)

    0 讨论(0)
  • 2020-12-13 04:06

    You can publicly expose Input facade via an alias in config/app.php:

    'aliases' => [
        ...
    
        'Input' => Illuminate\Support\Facades\Input::class,
    ]
    

    And access url $_GET parameter values using the facade directly inside Blade view/template:

    {{ Input::get('a') }}
    
    0 讨论(0)
  • 2020-12-13 04:07

    This works fine for me:

    {{ app('request')->input('a') }}
    

    Ex: to get pagination param on blade view:

    {{ app('request')->input('page') }}
    
    0 讨论(0)
提交回复
热议问题