【问题标题】:Laravel - Livewire, how to customize the global message URL?Laravel - Livewire,如何自定义全局消息 URL?
【发布时间】:2021-12-01 20:08:03
【问题描述】:

使用如下示例的自定义域并不会告诉 Livewire 请求在此示例中以相同的子域 subdomain1 为前缀:

    Route::domain('subdomain1.'.env('APP_DOMAIN', 'localhost'))
             ->middleware(['web',.....])
             ->as('app.')
             ->group(base_path('routes/app.php'));

问题在于 Livewire 获取端点的默认回调 /livewire/message/{message} 不幸的是仅使用根域,而不是基于调用它的位置。在我的情况下来自subdomain1,你可以猜到这意味着会话包的不同存储。首先是不同的会话。

因此,存储在子域的会话中与存储在会话本身中是不同的。尽管如此,为了根据每个子域封装 Livewire 使用,我还需要进行其他自定义,图像我有一个基于多租户的项目,我需要这样的隔离。

【问题讨论】:

    标签: php laravel laravel-livewire livewires


    【解决方案1】:

    经过一番谷歌搜索并基于Livewire forums中的解决方案:

    我对其进行了定制,使其适合子域使用

    • 第一步,在routes/app.php添加新路由:
    use Livewire\Controllers\HttpConnectionHandler;
    
    // .....
    // Notice that this root route has to be the same as the one in step2:
    Route::get('/', [AppController::class, 'index'])->name('app.index');
    // .....
    
    Route::post('livewire/message/{name}', [HttpConnectionHandler::class, '__invoke']);
    
    • Step2,在 Blade 中 @livewireScripts 之后:
    @livewireScripts
    <script>
        window.livewire_app_url = '{{route('app.index')}}';
    </script>
    

    如果您想知道 Livewire 的配置,则无需更改它。保持原样; null:

    'asset_url'  => null,
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-24
      • 2020-12-05
      • 2013-12-26
      • 1970-01-01
      • 2014-08-13
      • 2014-05-31
      • 2017-06-28
      • 2017-12-13
      相关资源
      最近更新 更多