1
我正在開發laravel 5.2項目,並遇到會話問題。創建會話時,我只能從刀片模板訪問它。如果我想從任何其他類訪問它,這是不可能的。我使用Laravel 5.2,我的所有路由都在'網絡'中間件內。我搜索了整個網絡,但沒有一個能夠解決我的問題。Laravel 5.2會話無法正常工作
會話創建代碼:
<?php namespace App\Lib\Services;
$this->request->session()->put('errors', $this->errors);`
redirect()->back()->send();
當我像下面的查看測試會話,它的工作原理(給出了預期的數據):
@extends('themes.backend.metronic.main')
@section('pageContent')
{{ dd(session ('errors')) }}
@endsection
但是,如果我想使用它另一類如下,它返回空:
namespace App\Lib\Themes\Errors;
function __construct($specs)
{
parent::__construct($specs);
$this->setData();
dd(session('errors')); // this returns null value
$this->setErrorMsg();
}
有人可以幫我解決這個問題嗎?
當你的類被構造時,會話數據是空的,所以你就會得到null。你有沒有試過從任何其他功能訪問它? –
創建你的會話像會話('key','value');並使用它像會話('鍵'); –
或者會話('key','value')方法不起作用。除了視圖以外,我無法使用任何會話。 – laravel