laravel 5.2 How to get route parameter in blade?

后端 未结 4 358
春和景丽
春和景丽 2021-02-03 19:06

this is my url http://project.dev/blogs/image-with-article so, here I need the parameter image-with-article in my blade to display which is a parameter

相关标签:
4条回答
  • 2021-02-03 19:50

    In Laravel 8, you can simply use request()->route('parameter_name').

    0 讨论(0)
  • 2021-02-03 19:51

    Easy way Just {{ dd(request()->query("PARAMNAME")) }}

    for get all PARAMs {{ dd(request()->query()) }}

    0 讨论(0)
  • 2021-02-03 20:04

    I'm not sure what you mean. If you're trying to construct the route in a Blade template, use

    <a href="{{ route('blog.by.slug', ['slug' => 'someslug']) }}">...</a>
    

    If you're trying to access the given parameter, I would suggest passing it from the controller:

    // CmsController
    public function show($slug)
    {
        // other stuff here
        return view('someview', compact('slug'));
    }
    
    // someview.blade.php
    {{ $slug }}
    

    And if you really need to access the parameter from the view without first sending it from the controller... you really shouldn't, but you can use the facade:

    {{ Request::route('slug') }}
    
    0 讨论(0)
  • 2021-02-03 20:04

    If you want to get the parameters without using the controller method

    {{dd(request()->route()->parameters)}}
    
    0 讨论(0)
提交回复
热议问题