Vahn Marty
Vahn Marty

Reputation: 1478

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.

Example: My site is http://dns.dev, if I will create a subdomain 'test' and click the button 'Create directory', then it redirect to http://test.dns.dev

I have this route for subdomains.

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

In my controller,

<?php

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";
        $directory->save();

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


    }
}

Upvotes: 1

Views: 5106

Answers (1)

Manh Nguyen
Manh Nguyen

Reputation: 940

Try this

$url = 'http://yourdomainname.com';
return Redirect::to($url);

Upvotes: 5

Related Questions