samedi 1 avril 2017

Laravel 5.4 - How to setup a optional parameter in a route. If it exists must be the word "home"?

I have the follow code from Laravel routes:

Route::group(['prefix'=>'{account}'], function (){

    Route::group(['prefix'=>'{location}'], function (){

        Route::get('/{home?}', function ($account,$location) { 
            $loc=explode("_", $location);
            $locale = $loc[0];
            $country= $loc[1]; 
            App::setLocale($locale);
            return view('homeProfPublic')->with(['account' => $account,'active' => 'home','locale'=>$locale,"country"=>$country]);  
        })->where('home', '/home/');
   });
});

I want this route to catch:

  1. mysite.com/bob/US_en
  2. http://ift.tt/2ovpMO8
  3. http://ift.tt/2onWZOj

In other words I want the word "home" to be optional, but if it is there, to be only the word "home". All previuos route should redirect to the home page.

  1. http://ift.tt/2ovaiK9 //Should redirect to contact page.

How can I accomplish this task?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire