0

How can I pass parameter to a controller from a route in laravel?

This is my route:

Route::get('/{slug}','SampleController@showCms'); 

This is my controller function:

public function showCms($slug){} 

I want to route '/' also from this slug:

route(Route::get('/{slug}','SampleController@showCms')) 

How can this be accomplished?

7
  • What is route(Route::get('/{slug}','SampleController@showCms')) supposed to be? Both routes are the same, what exactly are you trying to do? Commented Sep 19, 2014 at 11:02
  • Route::get('/{slug}','SampleController@showCms') this olny i am trying public function showCms($slug){} is controller function.I want this function also for Route('/','SampleController@showCms') this route also. Commented Sep 19, 2014 at 11:06
  • Ok, but what do you want to do? What is the problem? Is your solution not working as expected? I'm not sure I understand your question... Commented Sep 19, 2014 at 11:07
  • Exactly, i don't see any problem. Just pass /{some-data} and return $slug from your controller. It should work Commented Sep 19, 2014 at 11:08
  • but the url is localhost/website/public.it produce error.but localhost/website/public{some-thing} is work. Commented Sep 19, 2014 at 11:10

1 Answer 1

1

If you do

Route::get('{slug?}','SampleController@showCms'); 

Both

http://site.dev/ 

and

http://site.dev/this-is-my-slug 

Will cause a hit on your controller

public function showCms($slug = null) { if ($slug) { /// you got a slug here } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.