Support the ongoing development of Laravel.io →
Requests Views Forms
Last updated 2 years ago.
0

You want to use "make" to build the view from the controller. Then you can set and pass variables to views and templates.

For my example assume the view lives at this path:

views/myViews/the_view.blade.php

... and assuming the template lives at this path:

views/templates/master.blade.php


<?php

class YourController extends BaseController {

public $restful = true;
public $layout = 'templates.master';

public function reportProfileStore() {

//All the stuff you want to do here 

//Load the view with make
$view = View::make('myViews.the_view');
$view->viewVariableYouWant = 'Pass me to view';
$view->report_profiles = $report_profiles;

$this->layout->masterLayoutVariableYouWant = 'Pass me to template'
$this->layout->content = $view;

}
}

In the last line of that example I am setting the $view values to the template using a variable called content. Just make sure your master template is dumping that content variable somewhere..... eg

<body>
	<div id="container">
		<div id="nav-bar">@include('templates.navbar')</div>		
		<div id="top-bar">
			<a href="/"><img id="logo" src="images/skin/logo.png" /></a>
		</div>
                <div id="example">{{$masterLayoutVariableYouWant}}</div>
		<div id="main-content">{{$content}}</div>
		<div id="footer-container">@include('templates.footer')</div>
	</div>
</body>

Then your view looks like this

<h1>My View</h1>

<p>{{$viewVariableYouWant}}</p>

<ul>
@foreach($report_profiles as $profile)
	<li>
		{{$profile->id}}
	</li>
@endforeach
</ul> 
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

richoid richoid Joined 12 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.