Laravel 8处理子域路由,但它不起作用,我对此有些困惑

发布于 2025-01-25 04:53:02 字数 548 浏览 3 评论 0原文

我正在研究一个项目,每个用户将有单独的子域,例如我的网站名称是xyz.com,然后对于用户,它将是user.xyz.com,因为我试图进行子域路由,但它不起作用。

以下是以下主要领域的路线

 Route::get('/', function () {
    return redirect('login');
});

Auth::routes();

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

是子域的路线

 Route::domain('user.xyz.com')->group(function () {
    Route::get('/posts', function () {
        return 'Second subdomain landing page';
    });
   
});

任何专家,请研究一下。 欢迎建议。

I'm working on a project where for each user there will be separate subdomain for example my website name is xyz.com then for user it will be user.xyz.com, for that im trying to do subdomain routing but its not working.

Below are the routes for main domain

 Route::get('/', function () {
    return redirect('login');
});

Auth::routes();

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

Below are routes for subdomain

 Route::domain('user.xyz.com')->group(function () {
    Route::get('/posts', function () {
        return 'Second subdomain landing page';
    });
   
});

Any expert please look into this.
Suggestions are welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诺曦 2025-02-01 04:53:02

我有一个建议...为什么不将域作为参数传递,以您未知的方式,例如/article/article/{id}的文章ID?

尝试以下操作:

Route::domain('{user}.xyz.com')->group(function () {
    Route::get('/posts', [PostsController::class, 'view'])->name('posts');
});

在我们的post -scontroller输出结果...

class PostsController {
    public function view ($user){
        dd($user) //this will output the current user's subdomain name
    }
}

让我知道它是否适合您。

I have a suggestion... why not pass the domain as a parameter the way you would an unknown, article id for example /article/{id}?

Try this:

Route::domain('{user}.xyz.com')->group(function () {
    Route::get('/posts', [PostsController::class, 'view'])->name('posts');
});

In our PostsController output the results...

class PostsController {
    public function view ($user){
        dd($user) //this will output the current user's subdomain name
    }
}

Let me know if it works out for you.

城歌 2025-02-01 04:53:02

尝试在RouteserviceProvider中添加域线。

Route::middleware("web")->domain('Domain Name')->namespace($this->namespace)->group(base_path("routes/web.php"));

Try to add a domain line in RouteServiceProvider.

Route::middleware("web")->domain('Domain Name')->namespace($this->namespace)->group(base_path("routes/web.php"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文