Example #1
0
 /**
  * Display a listing of the resource. If the user is logged in they will see the position they took on votes
  *
  * @return Response
  */
 public function index()
 {
     $filters = Request::all();
     $limit = Request::get('limit') ?: 30;
     if (Auth::user()->can('create-votes')) {
         //Logged in user will want to see if they voted on these things
         $motions = Motion::with(['votes' => function ($query) {
             $query->where('user_id', Auth::user()->id);
         }]);
     } else {
         $motions = Motion::where('id', '>', 0);
     }
     if (isset($filters['rank_greater_than']) && is_numeric($filters['rank_greater_than'])) {
         $motions->rankGreaterThan($filters['rank_greater_than']);
     }
     if (isset($filters['rank_less_than']) && is_numeric($filters['rank_less_than'])) {
         $motions->rankLessThan($filters['rank_less_than']);
     }
     if (isset($filters['department_id']) && is_numeric($filters['department_id'])) {
         $motions->department($filters['department_id']);
     }
     if (isset($filters['is_active'])) {
         $motions->active($filters['is_active']);
     }
     if (isset($filters['is_expired'])) {
         $motions->expired($filters['is_expired']);
     }
     if (isset($filters['is_current'])) {
         $motions->current($filters['is_current']);
     }
     if (isset($filters['newest'])) {
         $motions->orderByNewest($filters['newest']);
     }
     if (isset($filters['oldest'])) {
         $motions->orderByOldest($filters['oldest']);
     }
     if (isset($filters['take'])) {
         $motions->take($filters['take']);
     } else {
         $motions->take(1);
     }
     return $motions->simplePaginate($limit);
 }