I am following a blog tutorial and i found this interesting blog route used to display a blog post
http://sweet-blog.herokuapp.com/interesting-articles-wide-pharmaceutical-and-produts
This is the migration file https://github.com/28harishkumar/blog/blob/master/database/migrations/2015_05_23_133926_posts.php
This is the function https://github.com/28harishkumar/blog/blob/master/app/Http/Controllers/PostController.php#L85
public function show($slug)
{
$post = Posts::where('slug',$slug)->first();
if($post)
{
if($post->active == false)
return redirect('/')->withErrors('requested page not found');
$comments = $post->comments;
}
else
{
return redirect('/')->withErrors('requested page not found');
}
return view('posts.show')->withPost($post)->withComments($comments);
}
and this is the route
https://github.com/28harishkumar/blog/blob/master/app/Http/routes.php#L62
Route::get('/{slug}',['as' => 'post', 'uses' => 'PostController@show'])->where('slug', '[A-Za-z0-9-_]+');
When i look at this lines
public function show($slug)
{
$post = Posts::where('slug',$slug)->first();
is laravel getting the slug for us without using $request to get the uri segment?
If so, how would we handle multiple parameters in the uri?.
/like/{$slug}/{$param}- linktoahref$slugparameter would contain the slug in the url, plus you need to pass an default value to the$slugvariable laravel.com/docs/5.4/routing#route-parameters - linktoahref/{$slug}/{$param}how would i access param? - user7851085public function show($slug = null, $param = null) { // you'll be able to access the $param variable in here- linktoahref