【问题标题】:route override the controller route with路由覆盖控制器路由
【发布时间】:2016-07-12 11:10:21
【问题描述】:

所以我试图将变量传递给我的视图,但我不知道 routes.php 中的默认路由如何覆盖 with 变量.. 让我更具体 在我看来,welcome 我有一个带有 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>

Routes.php [在网络组中]

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

我已经尝试将返回重定向更改为返回视图但不起作用并且已经 dd($tab) 但始终为空

我认为是因为 routes.php 但不确定... srry 为英国人,和 ty 的帮助

【问题讨论】:

    标签: laravel tabs routes blade laravel-5.2


    【解决方案1】:

    如果您使用return redirect()-&gt;route('index')-&gt;with('tab','login'),则数据会闪现到会话中。要获取视图中的数据,请使用 {{ session('tab') }}。更多信息here

    【讨论】:

    • 与其他答案相同。编辑后的帖子,不同标签的相同视图..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 2023-03-26
    • 2017-12-16
    • 1970-01-01
    相关资源
    最近更新 更多