Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created August 29, 2014 09:18
Show Gist options
  • Save coreymcmahon/4d332495f29f51dad64c to your computer and use it in GitHub Desktop.
Save coreymcmahon/4d332495f29f51dad64c to your computer and use it in GitHub Desktop.
Using the Repository Pattern - example 2 - http://www.slashnode.com/why-use-repository-pattern/
<?php
class PostController
{
public function index()
{
$posts = Post::where('date', '>', Carbon::now()->subDays(7))->get();
return View::make('users.show', compact('posts'));
}
// ...
}
class UserController
{
public function show($user_id)
{
$posts = Post::where('date', '>', Carbon::now()->subDays(7))
->where('user_id', $user_id)->get();
return View::make('users.show')
->with('users', User::find($user_id))
->with('posts', $posts);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment