jafar jafarnezhad
jafar jafarnezhad

Reputation: 39

Redirect to sub-domain with route parameter in laravel

How can I show for example this route "example.com/parameter" to this "parameter.example.com" for site visitors . the back-end of site is laravel 5.3 and web server is Apache. I want to use parameter in laravel controller.

Upvotes: 0

Views: 903

Answers (1)

James
James

Reputation: 441

You can set up a subdomain route like this:

Route::group(['domain' => '{parameter}.example.com'], function () {
    Route::get('/', 'UserController@showByParameter');
});

then in your controller you can do

public function showByParameter($parameter)
{
    $user = \App\User::whereParameter($parameter)->firstOrFail();

    return view('users.show', compact('user'));

}

Upvotes: 1

Related Questions