nematite
nematite

Reputation: 45

Laravel regex route

I would like to call one function from a controller to all route begin with my_website/doc/.

But I can't find something that to do that in laravel 5.

something like: Route::get('my_website/doc/*', 'WelcomeController@doc');

for exemple:

my_website/doc/test --> WelcomeController@doc

my_website/doc/test/1 --> WelcomeController@doc

my_website/doc/test/1/etc --> WelcomeController@doc

Upvotes: 1

Views: 607

Answers (2)

Roham Tehrani
Roham Tehrani

Reputation: 2989

This is another approach to solve the problem:

Route::get('{slug}', function($slug){
    dd($slug);
    //
})->where('slug', 'my_website/docs.*');

Upvotes: 1

Nyan Lynn Htut
Nyan Lynn Htut

Reputation: 657

You can use like this

Route::get('my_website/docs/{page?}', 'WelcomeController@doc');

{page?} will be

  • test for my_website/doc/test
  • test/1 for my_website/doc/test/1
  • test/1/etc for my_website/doc/test/1/etc

At doc method

public function doc($page = null)
{
    dd($page);
}

Upvotes: 1

Related Questions