簡體   English   中英

Laravel - Livewire,如何自定義全局消息 URL?

[英]Laravel - Livewire, how to customize the global message URL?

在此示例中,使用像下面示例這樣的自定義域並不會告訴 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 使用,我還需要其他自定義,圖像我有一個基於多租戶的項目,我需要這樣的隔離。

經過一些谷歌搜索並基於Livewire 論壇中的解決方案:

我將它定制為合適的子域使用

  • 第 1 步,在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,在@livewireScripts之后的@livewireScripts
@livewireScripts
<script>
    window.livewire_app_url = '{{route('app.index')}}';
</script>

如果您想知道 Livewire 的配置,則無需更改它。 保持原樣; null

'asset_url'  => null,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM