user2214646 user2214646 - 4 months ago 16
PHP Question

How can i get group parameter in laravel controller

URL: abc.example.com/page/first/second


I need 'abc','first' and 'second' values in my controller.

route.php



Route::group(['domain' => '{sub}.example.com'], function ()
{
Route::get('page/{param1}/{param2}', MyController@index);
});


MyCotroller.php



public function index($a,$b)
{
echo "Param1=".$a;
echo "Param2=".$b;
}


How can i get subdomain name in controller

Answer

Use like this

 public function index($sub,$a,$b)
{
  echo "Param1=".$a;
  echo "Param2=".$b; 
  echo "Sub =".$sub;
}

Remember first variable will be from group .

Better then this , use request

 public function index(Request $request)
{
  echo "Param1=".$request->a;
  echo "Param2=".$request->b; 
  echo "Sub =".$request->sub;
}