/**
  * Display a listing of the resource.
  * GET /admin/users
  *
  * @return Response
  */
 public function index()
 {
     $users = User::withTrashed();
     foreach (Input::all() as $key => $input) {
         if (in_array($key, ['vehicle_type', 'mark', 'model', 'body_type'])) {
             $users->whereHas('cars', function ($q) use($key, $input) {
                 $q->where($key, $input);
             });
         } elseif ($key == 'city') {
             $users->where($key, $input);
         }
     }
     $users = $users->with('cityRef')->paginate();
     return View::make('admin.users.index', ['title' => 'Пользователи', 'columns' => ['ID', 'Аватар', 'Имя', 'Почта', 'Номер телефона', 'Город', 'Возраст', 'Сообщений', 'Удален в', '', ''], 'data' => $users->transform(function ($user) {
         return ['id' => $user->id, 'img' => "<img src='{$user->img_small}'>", 'name' => link_to_action('AdminUsersController@show', $user->name, [$user->id]), 'email' => $user->email, 'phone' => $this->returnIfPresent($user, 'phone', 'number'), 'city' => $this->returnIfPresent($user, 'cityRef', 'ru'), 'age' => $user->birthday, 'messages' => $user->messages()->count(), 'deleted' => $user->deleted_at, 'edit' => link_to_action('AdminUsersController@edit', 'ред', [$user->id]), 'delete' => link_to_action('AdminUsersController@edit', 'удал', [$user->id])];
     }), 'links' => $users->links(), 'actions' => [link_to('#modal1', 'Разослать', ['class' => 'btn btn-primary btn-md margin']), link_to('#modal1', 'Опубликовать в ленту', ['class' => 'btn btn-primary btn-md margin']), link_to('#model1', 'Удалить выбранное', ['class' => 'btn btn-primary btn-md margin'])], 'filters' => [['param' => 'city', 'name' => 'Город', 'data' => CityRef::all()->transform(function ($city) {
         return ['id' => $city->id, 'name' => $city->ru];
     }), 'active' => Input::get('city')], ['param' => 'vehicle_type', 'name' => 'Тип Авто', 'data' => VehicleTypeRef::all()->transform(function ($v) {
         return ['id' => $v->id, 'name' => $v->ru];
     }), 'active' => Input::has('vehicle_type')], ['param' => 'mark', 'name' => 'Марка', 'data' => MarkRef::all()->transform(function ($m) {
         return ['id' => $m->id, 'name' => $m->name];
     }), 'active' => Input::has('mark')], ['param' => 'model', 'name' => 'Модель', 'data' => ModelRef::all()->transform(function ($m) {
         return ['id' => $m->id, 'name' => $m->name];
     }), 'active' => Input::Has('model')], ['param' => 'body_type', 'name' => 'Кузов', 'data' => BodyTypeRef::all()->transform(function ($b) {
         return ['id' => $b->id, 'name' => $b->ru];
     }), 'active' => Input::has('body_type')]]]);
 }
function pageController()
{
    if (Input::Get($counter)) {
        $counter = Input::Has($counter);
    } else {
        $counter = 0;
    }
    $data = ['counter' => $counter];
    return $data;
}