我有一个Laravel Blade表单,该表单未在production site上显示Flash会话错误消息。以前曾给出419错误响应“对不起,您的会话已过期。请刷新并在生产laravel上重试。”我能够清除该内容,因此可以通过清除缓存和作曲家dump-autoload来提交表单。
这是显示会话的表单。在本地工作,我在L5.7.9上。
<form method="POST" action="{{ route('candidates.store') }}" class="form">
@csrf
@if(session('message'))
<div class="alert alert-success">
{{ session('message') }}
</div>
@endif
@if (session('login_error'))
<div class="alert alert-danger" role="alert">
{{ session('login_error') }}
</div>
@endif
@if ($errors->any())
<div class="alert alert-danger" role="alert">
Woops had some problems saving
</div>
@endif
在我的 .env 文件中,我有:
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_DOMAIN=employbl.com
QUEUE_DRIVER=sync
然后在控制器存储方法中,我有:
public function store(Request $request)
{
$validator = $request->validate([
'first_name' => 'required',
'last_name' => 'required',
'email' => 'email|required|unique:users',
'linkedin_url' => 'required|url',
'phone_number' => 'required',
'work_authorization' => 'required',
'city' => 'required',
'state' => 'required'
]);
$candidate = new User($request->all());
$candidate->active = false;
$candidate->save();
return redirect()->route('candidates.landing')->with('message', 'Successfully applied to join Employbl network!');
}
对于路线,我没有路线组:
Route::get('/candidates', 'CandidateController@landing')->name('candidates.landing');
Route::post('/candidates', 'CandidateController@store')->name('candidates.store');
php artisan route:list显示我只使用过一次Web中间件:
| | POST | candidates | candidates.store | App\Http\Controllers\CandidateController@store | web |
该Flash消息在本地运行,但是当我在生产环境中提交表单(与Laravel Forge一起部署)时,该表单提交但没有显示Flash消息。我该怎么做才能使会话消息出现在生产环境中,为什么会发生这种情况?
答案 0 :(得分:0)
您缺少一些方法来检查您是否有使用该名称的会话以及(获取)获取值的方法。
@if(session::has('message'))
<div class="alert alert-success">
{{ session::get('message') }}
</div>
@endif
@if (session::has('login_error'))
<div class="alert alert-danger" role="alert">
{{ session::get('login_error') }}
</div>
@endif
@if ($errors->any())
<div class="alert alert-danger" role="alert">
Woops had some problems saving
</div>
@endif
答案 1 :(得分:0)
是问题吗?
return redirect()
->route('candidates.landing')
->with('message', 'Successfully applied to join Employbl network!');
// I think with takes [](array) so,
return redirect()
->route('candidates.landing')
->with(['message' => 'Successfully applied to join Employbl network!']);
//
//
// But why are't you doing like this
//
//
return back()->with([
'message' => 'Successfully applied to join Employbl network!'
]);
//
//
//
// And yes Session::has('message') or \Session::has('message') is a good way to check in the blade
答案 2 :(得分:0)
事实证明,我需要运行php artisan cache:clear
才能摆脱现有的会话信息。此处更多信息:https://laracasts.com/discuss/channels/forge/419-error-when-submitting-form-in-production-sorry-your-session-has-expired-please-refresh-and-try-again#reply=494157