Reputation: 345
I am trying to push an array to the blade template in laravel 4 Controller name: AdminController
public function listCompanies()
{
$companyObj = new company();
$companies = $companyObj->getCompanies();
$this->layout->content = View::make('admin/main',$companies);
}
Template name: main.blade.php
<div class="container">
@yield('content')
@foreach ($companies as $company)
<p>This is company {{ $company['name'] }}</p>
@endforeach
</div>
The error I am getting is: Undefined variable: companies (View: C:\wamp\www\larvel-project\laravel\app\views\admin\main.blade.php)
Upvotes: 0
Views: 1310
Reputation: 1832
The view is expecting to receive an associative array which includes the index 'companies' and will turn that into $companies.
Any of the following should work for you:
$this->layout->content = View::make('admin/main', ['companies' => $companies]);
$this->layout->content = View::make('admin/main', compact('companies'));
$this->layout->content = View::make('admin/main')->with('companies', $companies);
Upvotes: 0