Vahn Marty Vahn Marty - 1 month ago 33
PHP Question

Laravel: How to redirect to subdomain using a Controller?

The function of my program is to create a subdomain/subdirectory. I have a directories table, once a user will create a subdomain it redirects to its subdomain.

My site is, if I will create a subdomain 'test' and click the button 'Create directory', then it redirect to

I have this route for subdomains.

Route::post('/create', 'DirectoryController@create');
Route::group(['domain' => '{subdomain}'], function () {
Route::get('/', function ($subdomain) {
return $subdomain;

In my controller,


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Redirect;

use App\Directory;

class DirectoryController extends Controller
public function create(Request $request)
$directory = new Directory;
$directory->domain = $request->subdomain;
$directory->status = "pending";

//redirect to $request->subdomain . ''
//something like that



Try this

$url = '';
return Redirect::to($url);