W
W
walkerstech2021-05-09 04:06:44
Laravel
walkerstech, 2021-05-09 04:06:44

Laravel wildcard subdomain not working?

I found out about the wildcard subdomain, having done everything according to the manual, the domain still does not hail.
Added an entry to the DNS server
Name Record type and IP
*.test.ru A 1.1.1.1
web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ShopController;

Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Route::domain('{domain}.test.ru')->group(function () {
    Route::get('/', [ShopController::class, 'index']);
});

ShopController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;

class ShopController extends Controller
{
    public function index($domain)
    {
        $user = User::where('domain', $domain)->first();

        if(!$user){
            return true;
        }else{
            return false;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
walkerstech, 2021-05-09
@walkerstech

In alias in apache config, specified *.test.ru
P018boj3sdU.jpg?size=970x397&quality=96&sign=9496b7cbdbeb78d7f05cc8495efb4874&type=album
PS test.ru is an example, i.e. main domain hid

P
pLavrenov, 2021-05-11
@pLavrenov

multi-tenancy package
tenancyforlaravel.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question