2016-03-24 175 views
0

所以即時嘗試將一個變量傳遞給我的看法,但我不知道如何在routes.php中的默認路由覆蓋with變量.. 讓我更具體 在我看來歡迎我有一個帶有4個選項卡(登錄,註冊,聯繫人和主頁(apresentacion文本))的選項卡內容,並且當用戶登錄失敗時,例如重定向時,他始終爲主選項卡,因爲它是活動選項卡。 即時通訊試圖通過我想要使該選項卡的選項卡的名稱。 所以..路由覆蓋控制器路由與

以我控制器

[登錄方法]

(...) 
if (Auth::attempt($credentials, true)) 
    return redirect()->route('choice'); 
return redirect()->route('index') 
    ->with('tab','login') 
    ->withInput(); 

[註冊方法]

(code) 
return redirect()->route('index') 
     ->with('tab','register') 
     ->withInput(); 

在視圖[標籤代碼]

{{ isset($tab) ? '' : $tab='home' }} 

<div class="tab-content"> 
    <div role="tabpanel" class="tab-pane content {{ $tab=='home' ? 'active' : '' }}" id="home"></div> 
    <div role="tabpanel" class="tab-pane content {{ $tab=='login' ? 'active' : '' }}" id="login"></div> 
    <div role="tabpanel" class="tab-pane content {{ $tab=='register' ? 'active' : '' }}" id="register"></div> 
    <div role="tabpanel" class="tab-pane content {{ $tab=='contact' ? 'active' : '' }}" id="contact"></div> 
</div> 

路線s.php [是網絡組]

Route::get('/', function() { 
    return view('welcome'); 
})->name('index'); 

我已經嘗試改變返回重定向返回看法,但不工作,並且已經DD($標籤),但總是空空的

我認爲這是因爲routes.php但不能確定... srry爲英語夥伴,ty爲幫助

回答

0

如果您使用return redirect()->route('index')->with('tab','login'),數據會閃現到會話中。要在您的視圖中獲取數據,請使用{{ session('tab') }}。更多信息here

+0

同樣的事情,像其他anwser .. 編輯後,相同的視圖爲不同的標籤.. – syszen