Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created January 14, 2014 06:14
Show Gist options
  • Save coreymcmahon/8413871 to your computer and use it in GitHub Desktop.
Save coreymcmahon/8413871 to your computer and use it in GitHub Desktop.
Building Testable Applications using the Repository Pattern - http://www.slashnode.com/the-repository-pattern/
<?php namespace Acme\Controllers;
use Acme\Storage\PostRepository;
class PostController extends BaseController {
private $postRepository;
public function __construct(PostRepository $postRepository = null)
{
$this->postRepository = ($postRepository === null) ? new PostRepository : $postRepository;
}
public function index()
{
$posts = $this->postRepository->paginate(20);
return View::make('post.index', compact('posts'));
}
public function show($id)
{
$posts = $this->postRepository->findOrFail($id);
return View::make('post.show', compact('post'));
}
// ... etc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment