Reputation: 16748
I'm creating a Laravel 4 webapp and got the following route:
Route::get('products/{whateverId}', 'ProductController@index');
This is my index-function in ProductController:
public function index($whateverId)
{
$products = Product::all();
$data['whateverId'] = $whateverId;
return View::make('products', compact('products'), $data);
}
In my view, this returns the following error:
<p>Product: {{ $data['product'] }}</p>
ErrorException Undefined variable: data (View: /Users/myuser/webapp/app/views/products.blade.php)
Upvotes: 1
Views: 54
Reputation: 87739
Try passing it as:
$data['whateverId'] = $whateverId;
$data['products'] = Product::all();;
return View::make('products', $data);
And you'll have acces to it as
{{ foreach($products as ...) }}
and
{{ $whateverId }}
Or you can
$products = Product::all();
$data['whateverId'] = $whateverId;
return View::make('products')
->with('products', $products)
->with('whateverId', $whateverId);
Upvotes: 1
Reputation: 9847
return View::make('products', compact('products'), "data"=>$data);
(or compact('data')
)
Upvotes: 3