Laravel 5.1 中的嵌套视图未从控制器接收数据

Nested view not receiving data from controller in Laravel 5.1

从文档中我们将数据从控制器传递到 laravel 中的视图的方式就像

return view('someview')->with('key', $data);

所以我尝试将我的查询结果传递给

查看
$data = DB::table('user')->where('confirmation_status',1)->get();
return view('admin.presidentConfirmed')->with('data',$data);

但是presidentConfirmed视图里面没有数据。 所以我尝试使用 {{ Session::all() }} 来查看会话中是否有任何内容。

没有...

所以我尝试通过

传递纯文本

return view('admin.presidentConfirmed')->with('test','value');

仍然没有...

似乎只发生在这个特定的视图上。因为我将 ->with() 与许多其他视图一起使用没有任何问题。

总统确认

@extends('layout.main')

@section('content')

@stop

layout.main

@include('layout/component.menu')

<div class="container" id="main_container">
  <div class="well">
    @yield('content')
  </div>
  @if(Config::get('app.debug') == true)
    <div class="well">
      {{ var_dump(Session::all()) }}
    </div>
  @endif
</div>
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
@yield('script')
@if(Config::get('applicationConfig.release') == 'release' && Config::get('applicationConfig.mode') != 'close' && Config::get('applicationConfig.mode') != 'technical_difficulties')
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-73122311-1', 'auto');
  ga('send', 'pageview');

</script>
@endif

来自 laravel docs :

Of course, views may also be nested within sub-directories of the resources/views directory. For example, if your view is stored at resources/views/admin/profile.php, it should be returned like so:

return view('admin.profile', $data);

所以,在你的情况下应该是:

return view('admin.presidentConfirmed',$data);

我想通了,实际上是我混淆了 ->with()Redirect:: 一起使用和 ->with()view()

一起使用

Redirect::to('/somepage')->with('key','value) 是将其数据存储在会话中并使用 Session::get('key') 检索数据的那个。

view('someview')->with('key','value') 不将其数据存储在会话中并使用 {{ $key }}

检索数据