Vahn Marty Vahn Marty - 2 years ago 248
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', '[email protected]');
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


Answer Source

Try this

$url = '';
return Redirect::to($url);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download