Skip to content

Instantly share code, notes, and snippets.

@baniol
Last active December 17, 2015 10:49
Show Gist options
  • Save baniol/5597766 to your computer and use it in GitHub Desktop.
Save baniol/5597766 to your computer and use it in GitHub Desktop.
example laravel controller & view (layout);
// taken from : http://forums.laravel.io/viewtopic.php?id=839
class Blog_Controller extends Controller
{
public $layout = 'layouts.default';
public function action_index()
{
$this->layout->title = "Blog";
$this->layout->content = View::make( 'blog::index' )->with( 'posts', Post::published()->paginate() );
}
public function action_author( $user_id )
{
$user = User::find( $user_id );
if( is_null( $user ) ) return Response::error( '404' );
$posts = Post::published_by_author( $user_id )->paginate();
$this->layout->title = "Blog | Viewing posts by $user->name";
$this->layout->content = View::make( 'blog::author' )->with( 'user', $user )->with( 'posts', $posts );
}
}
<html>
<head>
<title>{{ $title }}</title>
</head>
<body>
{{ $content }}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment