Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

php - laravel 5.2 How to get route parameter in blade?

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 named slug here is in my routes file I need the slug paramter in blade.

Route::get('/blogs/{slug}', ['as'=>'blog.by.slug', 'uses'=> 'CmsController@show']);
question from:https://stackoverflow.com/questions/39011648/laravel-5-2-how-to-get-route-parameter-in-blade

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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') }}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...