1
我有一個窗體運行此控制器代碼;會話閃存不工作
public function index()
{
$date = date("Ymd");
$temp_table = new TempTable;
$generated_temp_table = $_POST['generated_temp_table'];
$temp_table_data = $temp_table->setTempTable($generated_temp_table)->newQuery()->with('payment')->get();
$payments = [];
foreach($temp_table_data as $a_payment) {
array_push($payments, $a_payment->payment->first()->attributesToArray());
}
//then create the Excel file
Excel::create($date.'-SME_Payments_Export-U', function($excel) use ($payments) {
$excel->sheet('Excel sheet', function($sheet) use ($payments) {
$sheet->setOrientation('landscape');
$sheet->fromArray($payments);
});
})->export('csv');
\Session::flash('flash_message', 'Your CSV is downloading');
Redirect::back();
}
flash
消息未顯示。這裏是視圖代碼;
@if(Session::has('flash_message'))
<div class="alert alert-success {{Session::has('flast_message_important') ? 'alert-important' : ''}}">
@if(Session::has('flash_message_important'))
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
@endif
{{ session('flash_message')}}
</div>
@endif
我已經在兩個控制器的頂部包含了use Session;
。這裏是在config/app.php中;
'Session' => 'Illuminate\Support\Facades\Session',
有沒有比我在這裏嘗試的更多呢?
您是否在加載頁面期間發出任何ajax請求?如果是這樣,Session :: flash會使數據僅用於當前和下一個請求(僅限!)。如果您創建Session :: flash(),則該消息仍然可用,但是如果在頁面加載期間完成了Ajax請求。數據不可用,因爲ajax請求消耗了數據。 – ChainList