Ad

Nested View Not Receiving Data From Controller In Laravel 5.1

From the documentation the way we pass data from controller to view in laravel is like

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

So I try to pass my query results to view by

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

But at the presidentConfirmed view, there's no data in it. So I tried to use {{ Session::all() }} to see if there's anything in the session.

Nothing...

So I tried passing just plain text through with

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

Still nothing...

It's seems to only happen to only this specific view. Since I use ->with() with many other views without any problem.

presidentConfirmed

@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
Ad

Answer

I figured that out, it's actually me that confused ->with() that use with Redirect:: and ->with() that use with view()

Redirect::to('/somepage')->with('key','value) is the one that stores its data in a session and use Session::get('key') to retrieve the data.

view('someview')->with('key','value') doesn't store its data in a session and retrieve the data with {{ $key }}

Ad
source: stackoverflow.com
Ad