2016-07-24 194 views
1

這是我的routes.php文件:Laravel 5.2閃存會話不工作

Route::get('advertise', ['as' => 'advertise', 'uses' => '[email protected]']); 

這裏是App\Exceptions\Handler.php文件的相關部分:

public function render($request, Exception $e) 
{ 
    switch ($e) 
    { 
     case ($e instanceof AdvertiserNotFoundException): 
      return redirect()->route('advertise')->with('status', 'Advertiser not found.'); 
     default: 
      return parent::render($request, $e); 
    } 
} 

這裏是我如何(試圖)顯示以下信息:

@if (session('status')) 
    <div class="alert alert-success"> 
     {{ session('status') }} 
    </div> 
@endif 

它是正確捕捉AdvertiserNotFoundException和重定向到路由advertise,但響應沒有攜帶任何閃存數據。

我不包括網絡中間件,因爲默認情況下所有路由都被它覆蓋。

EDIT 1

這裏的錯誤日誌,如果有幫助:

[2016-07-24 14:31:59] local.ERROR: exception 'App\Exceptions\AdvertiserNotFoundException' in C:\MyApp\app\Providers\RouteServiceProvider.php:31 Stack trace: 
#0 [internal function]: App\Providers\RouteServiceProvider->App\Providers\{closure}('12d5763b-2a16-4...') 
#1 C:\MyApp\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1003): call_user_func(Object(Closure), '12d5763b-2a16-4...') 
#2 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}('12d5763b-2a16-4...', Object(Illuminate\Routing\Route)) 
#3 C:\MyApp\vendor\laravel\framework\src\Illuminate\Routing\Router.php(885): call_user_func(Object(Closure), '12d5763b-2a16-4...', Object(Illuminate\Routing\Route)) 
#4 C:\MyApp\vendor\laravel\framework\src\Illuminate\Routing\Router.php(838): Illuminate\Routing\Router->performBinding('advertiser', '12d5763b-2a16-4...', Object(Illuminate\Routing\Route)) 
#5 C:\MyApp\vendor\laravel\framework\src\Illuminate\Routing\Router.php(825): Illuminate\Routing\Router->substituteBindings(Object(Illuminate\Routing\Route)) 
#6 C:\MyApp\vendor\laravel\framework\src\Illuminate\Routing\Router.php(691): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request)) 
#7 C:\MyApp\vendor\laravel\framework\src\Illuminate\Routing\Router.php(675): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) 
#8 C:\MyApp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(246): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) 
#9 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request)) 
#10 C:\MyApp\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#11 C:\MyApp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(44): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#12 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#13 C:\MyApp\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(136): call_user_func_array(Array, Array) 
#14 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#15 C:\MyApp\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#16 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#17 C:\MyApp\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#18 C:\MyApp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(132): Illuminate\Pipeline\Pipeline->then(Object(Closure)) 
#19 C:\MyApp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(99): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) 
#20 C:\MyApp\public\index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) 
#21 {main} 

回答

0

with()函數用於通數據從控制器的圖。

您需要使用會話如下設置數據:

case ($e instanceof AdvertiserNotFoundException): 
    session('status', 'Advertiser not found.'); 
    return redirect()->route('advertise'); 
+0

感謝,但它仍然無法正常工作,該會議是空的。 – RektByAyyLMAO

+0

你的Laravel版本是什麼? –

+0

對於在會話中設置新密鑰,您必須將關聯數組傳遞給會話函數,如下所示:'session(['key'=>'value'])' 您的書寫代碼返回'找不到廣告客戶'。如果會話沒有'狀態'鍵 – Morilog