You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 10+Jetstream:在用户个人中心永久显示邮箱已验证提示

解决方案

1. 修正语法并编写邮箱已验证提示逻辑

你提供的代码是HTML转义后的内容,直接放入blade文件会引发语法错误,需先还原转义字符,再编写与未验证逻辑相反的判断代码:

@if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::emailVerification()) && $this->user->hasVerifiedEmail())
    <p class="text-sm mt-2 text-green-600">
        {{ __('您的邮箱已验证') }}
    </p>
@endif

2. 正确放置代码位置

打开resources/views/profile/update-profile-information-form.blade.php,将上述代码插入到表单的合适位置(比如表单标题下方),示例如下:

<x-form-section submit="updateProfileInformation">
    <x-slot name="title">
        {{ __('Profile Information') }}
    </x-slot>

    <x-slot name="description">
        {{ __('Update your account\'s profile information and email address.') }}
    </x-slot>

    <!-- 插入邮箱已验证提示 -->
    @if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::emailVerification()) && $this->user->hasVerifiedEmail())
        <p class="text-sm mt-2 text-green-600">
            {{ __('您的邮箱已验证') }}
        </p>
    @endif

    <!-- 保留原有未验证提示(可选) -->
    @if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::emailVerification()) && ! $this->user->hasVerifiedEmail())
        <p class="text-sm mt-2 text-yellow-600">
            {{ __('Your email address is unverified.') }}
        </p>
    @endif

    <x-slot name="form">
        <!-- 原有表单内容 -->
    </x-slot>

    <x-slot name="actions">
        <!-- 原有按钮内容 -->
    </x-slot>
</x-form-section>

3. 排查常见错误

  • 若出现$this->user不存在的报错,替换为Auth::user(),记得先引入门面:
    @php
        use Illuminate\Support\Facades\Auth;
    @endphp
    
    @if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::emailVerification()) && Auth::user()->hasVerifiedEmail())
        <p class="text-sm mt-2 text-green-600">
            {{ __('您的邮箱已验证') }}
        </p>
    @endif
    
  • 确认config/fortify.php中emailVerification功能已启用:
    'features' => [
        Features::registration(),
        Features::resetPasswords(),
        Features::emailVerification(), // 确保此行存在
        Features::updateProfileInformation(),
        // 其他功能
    ],
    

内容的提问来源于stack exchange,提问作者Webdesignbr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 05:53:34