Created
March 28, 2014 18:12
-
-
Save mattaebersold/9839292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class GadgetController extends BaseController { | |
// Default per page | |
const PER_PAGE = 10; | |
// Homepage feed | |
public function index($filter = null) { | |
// Tell Laravel where to find the mustache views for post | |
app('view')->addNamespace('js', public_path().'/js'); | |
// Render the view | |
$this->layout->nest('content', 'gadget.index', array( | |
'posts' => Post::filter($filter)->ordered()->visible()->take(self::PER_PAGE)->where('type', '=', 'youtube')->get(), | |
'filters' => Filter::ordered()->get(), | |
)); | |
} | |
// Return more via ajax | |
public function more() { | |
// Get params | |
$per_page = Input::get('per-page', self::PER_PAGE); | |
$filter = Input::get('filter'); | |
// Build query | |
if ($filter) $posts = Filter::findBySlugOrFail($filter)->posts(); | |
else $posts = Post::query(); | |
// Return list | |
return $posts->ordered() | |
->visible() | |
->take($per_page) | |
->where('type', '=', 'youtube') | |
->skip((Input::get('page', 1)-1) * $per_page) | |
->get(); | |
} | |
// Return data for modal | |
public function modal($slug) { | |
return Post::findBySlugOrFail($slug)->addSiblings(Input::get('filter'))->addRelated(Input::get('filter')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment