Question

I'm writing a simple app which only relies on a few routes and views. I've setup an overall layout and successfully nested a template using the following.

routes.php

View::name('layouts.master', 'master');
$layout = View::of('master');

Route::get('/users', function() use ($layout)
{
    $users = Users::all()
    return $layout->nest('content','list-template');
});

master.blade.php

<h1>Template</h1>
<?=$content?>

list-template.php

foreach($users as $user) {
   echo $user->title;
}

How do I pass the query results $users into my master template and then into list-temple.php?

Thanks

Était-ce utile?

La solution

->nest allows a 3rd argument for an array of data:

   Route::get('/users', function() use ($layout)
    {
        $users = Users::all()
        return $layout->nest('content','list-template', array('users' => $users));
    });

Also in your master.blade.php file - change it to this:

<h1>Template</h1>
@yield('content')

list-template.blade.php <- note the blade filename:

@extends('layouts.master')

@section('content')
<?php
  foreach($users as $user) {
     echo $user->title;
   }
?>
@stop
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top