2018-01-20 06:07:31 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Frontend;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Controller;
|
2018-09-03 08:12:11 +08:00
|
|
|
use App\Models\Enums\UserState;
|
|
|
|
use App\Repositories\Criteria\WhereCriteria;
|
2018-01-20 06:07:31 +08:00
|
|
|
use App\Repositories\UserRepository;
|
|
|
|
use Illuminate\Http\Request;
|
2020-04-07 00:03:19 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use League\ISO3166\ISO3166;
|
2018-09-03 08:12:11 +08:00
|
|
|
use Prettus\Repository\Exceptions\RepositoryException;
|
2018-01-20 06:07:31 +08:00
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
|
|
|
private $userRepo;
|
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
/**
|
|
|
|
* @param UserRepository $userRepo
|
|
|
|
*/
|
2020-04-07 00:03:19 +08:00
|
|
|
public function __construct(UserRepository $userRepo)
|
|
|
|
{
|
2018-01-20 06:07:31 +08:00
|
|
|
$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
|
2018-01-20 06:07:31 +08:00
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
2018-09-03 08:12:11 +08:00
|
|
|
$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'])
|
2020-04-07 00:03:19 +08:00
|
|
|
->orderBy('pilot_id', 'asc')
|
2018-09-03 08:12:11 +08:00
|
|
|
->paginate();
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
return view('users.index', [
|
2020-04-07 00:03:19 +08:00
|
|
|
'country' => new ISO3166(),
|
2018-09-03 08:12:11 +08:00
|
|
|
'users' => $users,
|
2018-01-20 06:07:31 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|