simple user search and pagination
This commit is contained in:
@@ -2,19 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\Airline;
|
||||
use App\Models\FlightFields;
|
||||
use App\Models\Airport;
|
||||
use App\Http\Requests\CreateFlightRequest;
|
||||
use App\Http\Requests\UpdateFlightRequest;
|
||||
use App\Repositories\AirlineRepository;
|
||||
use App\Repositories\AirportRepository;
|
||||
use App\Repositories\FlightRepository;
|
||||
use App\Repositories\SubfleetRepository;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Flash;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
use Response;
|
||||
|
||||
class FlightController extends BaseController
|
||||
|
||||
@@ -8,10 +8,8 @@ use App\Repositories\UserRepository;
|
||||
use DB;
|
||||
use Hash;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Flash;
|
||||
use Jackiedo\Timezonelist\Facades\Timezonelist;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
use Response;
|
||||
|
||||
use App\Models\Airport;
|
||||
@@ -38,10 +36,11 @@ class UserController extends BaseController
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->userRepo->pushCriteria(new RequestCriteria($request));
|
||||
$users = $this->userRepo->searchCriteria($request, false)->paginate();
|
||||
/*$this->userRepo->pushCriteria(new RequestCriteria($request));
|
||||
$users = $this->userRepo
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate();
|
||||
->paginate();*/
|
||||
|
||||
return view('admin.users.index', [
|
||||
'users' => $users,
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
|
||||
use App\Models\Flight;
|
||||
use App\Repositories\Criteria\WhereCriteria;
|
||||
use App\Repositories\Traits\CacheableRepository;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
|
||||
class FlightRepository extends BaseRepository implements CacheableInterface
|
||||
{
|
||||
@@ -28,7 +28,7 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
||||
|
||||
/**
|
||||
* Create the search criteria and return this with the stuff pushed
|
||||
* @param FormRequest $request
|
||||
* @param Request $request
|
||||
* @param bool $only_active
|
||||
* @return $this
|
||||
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<?php
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Enums\PilotState;
|
||||
use App\Models\User;
|
||||
use App\Repositories\Traits\CacheableRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Enums\PilotState;
|
||||
use App\Repositories\Criteria\WhereCriteria;
|
||||
use App\Repositories\Traits\CacheableRepository;
|
||||
|
||||
class UserRepository extends BaseRepository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
@@ -36,4 +39,31 @@ class UserRepository extends BaseRepository implements CacheableInterface
|
||||
$users = $this->orderBy('created_at', 'desc')->findWhere($where)->count();
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the search criteria and return this with the stuff pushed
|
||||
* @param Request $request
|
||||
* @param bool $only_active
|
||||
* @return $this
|
||||
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
||||
*/
|
||||
public function searchCriteria(Request $request, bool $only_active = true)
|
||||
{
|
||||
$where = [];
|
||||
|
||||
if($only_active) {
|
||||
$where['state'] = PilotState::ACTIVE;
|
||||
}
|
||||
|
||||
if ($request->filled('name')) {
|
||||
$where['name'] = $request->name;
|
||||
}
|
||||
|
||||
if ($request->filled('email')) {
|
||||
$where['email'] = $request->email;
|
||||
}
|
||||
|
||||
$this->pushCriteria(new WhereCriteria($request, $where));
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<th>Flight #</th>
|
||||
<th>Dep</th>
|
||||
<th>Arr</th>
|
||||
<th>Route</th>
|
||||
{{--<th>Route</th>--}}
|
||||
<th>Dpt Time</th>
|
||||
<th>Arr Time</th>
|
||||
<th>Notes</th>
|
||||
@@ -29,7 +29,7 @@
|
||||
(Alt: {!! $flight->alt_airport->icao !!})
|
||||
@endif
|
||||
</td>
|
||||
<td>{!! $flight->route !!}</td>
|
||||
{{--<td>{!! $flight->route !!}</td>--}}
|
||||
<td>{!! $flight->dpt_time !!}</td>
|
||||
<td>{!! $flight->arr_time !!}</td>
|
||||
<td>{!! $flight->notes !!}</td>
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
|
||||
@section('title', 'Users')
|
||||
@section('actions')
|
||||
<li>
|
||||
<a href="{!! route('admin.users.create') !!}">
|
||||
<i class="ti-plus"></i>
|
||||
Add New</a>
|
||||
<li><a href="{!! route('admin.users.index') !!}?search=state:0">
|
||||
<i class="ti-plus"></i>{!! PilotState::label(PilotState::PENDING) !!}</a>
|
||||
</li>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
@include('admin.users.search')
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
@include('admin.users.table')
|
||||
</div>
|
||||
|
||||
26
resources/views/admin/users/search.blade.php
Normal file
26
resources/views/admin/users/search.blade.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
{!! Form::open(['route' => 'admin.users.index', 'method' => 'GET', 'class'=>'form-inline pull-right']) !!}
|
||||
|
||||
{!! Form::label('name', 'Name:') !!}
|
||||
{!! Form::text('name', null, ['class' => 'form-control']) !!}
|
||||
|
||||
{!! Form::label('email', 'Email:') !!}
|
||||
{!! Form::text('email', null, ['class' => 'form-control']) !!}
|
||||
|
||||
{{--{!! Form::label('dep_icao', 'Departure:') !!}
|
||||
{!! Form::select('dep_icao', $airports, null , ['class' => 'form-control']) !!}
|
||||
|
||||
{!! Form::label('arr_icao', 'Arrival:') !!}
|
||||
{!! Form::select('arr_icao', $airports, null , ['class' => 'form-control']) !!}
|
||||
--}}
|
||||
{!! Form::submit('find', ['class' => 'btn btn-primary']) !!}
|
||||
|
||||
<a href="{!! route('admin.users.index') !!}">clear</a>
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user