Model: Comment.php
class Comment extends Eloquent {
protected $table = 'comments';
public $timestamps = true;
}
Controller: PageController.php
class PageController extends BaseController {
$top_comments = Comment::take(3)->get();
return View::make('page', array('top_comments' => $top_comments));
}
View: page.blade.php
@foreach ($top_comments as $comment)
user #{{ $comment->user_id }}:<br />
{{ $comment->comment}}
@endforeach
This works perfect with the page.blade.php
view which I can define as a route (/page
). However, I can't seem to figure out how to achieve this globally.
Example: I want to be able to use the @foreach
containing $top_comments
in my master.blade.php
file. Right now if I was to use the above, it works great on /page
but not on /
, /about
, /tos