Laravel Jetstream头像更新后重定向至原视图问题求助
解决Laravel Jetstream头像更新后重定向自定义视图的问题
问题出在Jetstream自带的UpdateProfileInformationForm Livewire组件中,头像更新逻辑里硬编码了重定向到原Profile视图的路由,而其他字段更新是通过Livewire本地刷新实现的。以下是具体解决步骤:
发布Jetstream的Livewire组件到本地项目
直接修改vendor目录下的组件会被框架更新覆盖,先执行命令将组件复制到项目可编辑目录:php artisan vendor:publish --tag=jetstream-livewire执行后,组件文件会生成在
app/Http/Livewire/Profile/UpdateProfileInformationForm.php修改组件中的重定向逻辑
打开上述文件,找到updateProfileInformation方法。默认代码中处理头像上传的部分会执行重定向:if ($this->photo) { $this->user->updateProfilePhoto($this->photo); // 这里是默认的重定向,需要修改 return redirect()->route('profile.show'); }将
route('profile.show')替换为你的自定义视图对应的路由名称,比如你的自定义视图路由名为profile.custom,则修改为:return redirect()->route('profile.custom');确认自定义视图的路由已定义
确保routes/web.php中存在自定义视图的路由,示例:Route::get('/custom-profile', [ProfileController::class, 'showCustom']) ->name('profile.custom') ->middleware(['auth', 'verified']);
完成以上操作后,头像更新保存后就会跳转到你的自定义视图,和其他字段更新的行为保持一致。
内容的提问来源于stack exchange,提问作者user2034593
相关产品推荐
相关产品推荐

