Laravel 6自定义邮箱验证报错:getFromJson方法不存在
Hey there! I’ve run into this exact issue before with Laravel 6, so let’s break down what’s going on and how to fix it quickly.
The Root Cause
Laravel 6 fully removed the getFromJson method from the Translator class—it was deprecated in earlier versions and replaced with simpler, more consistent helper functions. Your custom email verification setup is still calling this old method somewhere, which is throwing the error. Clearing just the view cache isn’t enough because the problem lives in your code or templates, not cached views.
Step-by-Step Fixes
Check your email verification views
Head toresources/views/auth/verify.blade.php(or any custom verification views you’ve created). Look for code snippets like:{{ trans()->getFromJson('auth.verify.title') }}Replace every instance of
getFromJsonwith either the__()helper ortrans():{{ __('auth.verify.title') }} {{-- OR --}} {{ trans('auth.verify.title') }}Update your custom Verification Notification
If you built a customVerifyEmailnotification (usually stored inapp/Notifications), open that file and check thetoMailmethod. You’ll likely see code like this:return (new MailMessage) ->line($this->translator->getFromJson('Please click the button below to verify your email address.')) ->action($this->translator->getFromJson('Verify Email Address'), $url);Swap out
getFromJsonwithtrans()or use the__()helper directly:return (new MailMessage) ->line(__('Please click the button below to verify your email address.')) ->action(__('Verify Email Address'), $url);Clear all caches (not just views)
Run these commands to ensure old cached code doesn’t interfere with your changes:php artisan config:clear php artisan route:clear php artisan cache:clearVerify your language files
Double-check that your language files (e.g.,resources/lang/en/auth.php) have the correct keys for your verification messages. This ensures the__()ortrans()functions can pull the right translations without issues.
Final Check
After making these updates, trigger the email verification flow again. The error should disappear once all old getFromJson calls are replaced with the current Laravel translation methods.
内容的提问来源于stack exchange,提问作者Moussa Eloifi

