phpvms/app/Http/Controllers/Frontend/UserController.php

61 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers\Frontend;
use App\Contracts\Controller;
use App\Models\Enums\UserState;
use App\Repositories\Criteria\WhereCriteria;
use App\Repositories\UserRepository;
use Illuminate\Http\Request;
use Log;
use Prettus\Repository\Exceptions\RepositoryException;
/**
* Class UserController
*/
class UserController extends Controller
{
private $userRepo;
2018-02-21 12:33:09 +08:00
/**
* UserController constructor.
2018-08-27 00:40:04 +08:00
*
2018-02-21 12:33:09 +08:00
* @param UserRepository $userRepo
*/
public function __construct(
UserRepository $userRepo
) {
$this->userRepo = $userRepo;
}
/**
2018-02-21 12:33:09 +08:00
* @param Request $request
2018-08-27 00:40:04 +08:00
*
2018-02-21 12:33:09 +08:00
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(Request $request)
{
$where = [];
if (setting('pilots.hide_inactive')) {
$where['state'] = UserState::ACTIVE;
}
try {
$this->userRepo->pushCriteria(new WhereCriteria($request, $where));
} catch (RepositoryException $e) {
Log::emergency($e);
}
$users = $this->userRepo
->with(['airline', 'current_airport'])
->orderBy('name', 'desc')
->paginate();
return view('users.index', [
'country' => new \League\ISO3166\ISO3166(),
'users' => $users,
]);
}
}