php - Laravel - Livewire,如何自定义全局消息 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,在 Blade 之后
@livewireScripts
:
@livewireScripts
<script>
window.livewire_app_url = '{{route('app.index')}}';
</script>
如果您想知道 Livewire 的配置,则无需更改它。保持原样;null
:
'asset_url' => null,
推荐阅读
- python - 在数组中的值之间插入不同数量的点
- reactjs - React + TailwindCSS 不显示背景图片
- scala - 使用 Akka Stream,如何动态复制流?
- javascript - 如何通过 Jest 测试测试从 JS 返回的 HTML span 元素?
- c++ - 在处理加载程序线程和大量数据时扩展关键部分的放置位置
- amazon-web-services - 如何将参数传递给嵌入在 serverless.yaml 文件中的 cloudformation 模板
- swift - “[插件] AddInstanceForFactory:没有为 id 注册工厂” - 与音频无关
- python - Python - 我尝试用scrapy抓取项目,但是图像链接没有抓取
- python - 如何导航到新的 url 而无需在 selenium 中打开新窗口(python)
- python - 使用 selenium python 从搜索栏中选择第一个元素