Fix: updated AdminController with pagination
This commit is contained in:
parent
ea1713cb14
commit
0d39327ee2
@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
||||
use App\Utilities\ApiCalls;
|
||||
use Session;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
@ -24,6 +26,58 @@ class AdminController extends Controller
|
||||
return redirect->back();
|
||||
}
|
||||
|
||||
|
||||
// 2. Define pagination parameters
|
||||
$perPage = 10;
|
||||
$currentPage = LengthAwarePaginator::resolveCurrentPage() ?: 1;
|
||||
$offset = ($currentPage - 1) * $perPage;
|
||||
|
||||
// 3. Slice the array to get the items for the current page
|
||||
$currentPageItems = array_slice($users_arr['data'], $offset, $perPage);
|
||||
|
||||
// 4. Create the LengthAwarePaginator instance
|
||||
$paginatedItems = new LengthAwarePaginator(
|
||||
$currentPageItems, // Items for the current page
|
||||
count($users_arr['data']), // Total number of items
|
||||
$perPage, // Items per page
|
||||
$currentPage, // Current page number
|
||||
['path' => request()->url(), 'query' => request()->query()] // Options to preserve query strings and path
|
||||
);
|
||||
$user_type_arr = [
|
||||
'district_user' => 'District User',
|
||||
'regional_user' => 'Regional User',
|
||||
'national_user' => 'National User'
|
||||
];
|
||||
$data = [
|
||||
'page_title' => 'User Admin',
|
||||
'users_arr' => $users_arr['data'],
|
||||
'regions_arr' => $regions_arr['data'],
|
||||
'user_type_arr' => $user_type_arr,
|
||||
'items' => $paginatedItems
|
||||
];
|
||||
// dump($data);
|
||||
// 5. Pass the paginator instance to your view
|
||||
return view('admin.paginated', $data);
|
||||
// return view('admin.home', $data);
|
||||
|
||||
}
|
||||
public function indexOld(){
|
||||
$users_url = "user_mgt/get_all_users.php";
|
||||
$data = ['api_token' => env('LUPMISAPIKEY')];
|
||||
$result = ApiCalls::CurlPost(json_encode($data), $users_url);
|
||||
$users_arr = json_decode($result, true);
|
||||
if ($users_arr['success'] == false) {
|
||||
return redirect->back();
|
||||
}
|
||||
|
||||
$regions_url = "user_mgt/get_all_regions.php";
|
||||
$data = ['api_token' => env('LUPMISAPIKEY')];
|
||||
$result = ApiCalls::CurlPost(json_encode($data), $regions_url);
|
||||
$regions_arr = json_decode($result, true);
|
||||
if ($regions_arr['success'] == false) {
|
||||
return redirect->back();
|
||||
}
|
||||
|
||||
$user_type_arr = [
|
||||
'district_user' => 'District User',
|
||||
'regional_user' => 'Regional User',
|
||||
|
||||
@ -4,6 +4,7 @@ namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Pagination\Paginator; // Import the Paginator class
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@ -15,5 +16,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
if (config('app.env') === 'production') {
|
||||
URL::forceScheme('https');
|
||||
}
|
||||
Paginator::useBootstrap();
|
||||
}
|
||||
}
|
||||
|
||||
85
php_code/resources/views/admin/paginated.blade.php
Normal file
85
php_code/resources/views/admin/paginated.blade.php
Normal file
@ -0,0 +1,85 @@
|
||||
@extends('layouts.master')
|
||||
@section('page-title')
|
||||
Admin | {{ $page_title }}
|
||||
@endsection
|
||||
@section('page-css')
|
||||
<link rel="stylesheet" href="{{ url('public/assets/libs/select2/dist/css/select2.css') }}">
|
||||
|
||||
@endsection
|
||||
@section('page-content')
|
||||
@include('admin.partials.create-user')
|
||||
@include('admin.partials.edit-user')
|
||||
@include('admin.partials.view-user')
|
||||
@include('layouts.partials.navbar')
|
||||
|
||||
|
||||
<div class="container py-4">
|
||||
<div class="main">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h3>Users</h3>
|
||||
<!-- <a href="" class="float-end">Add User</a> -->
|
||||
<div class="float-end pb-2" >
|
||||
<button type="button" class="btn btn-warning btn-sm" data-bs-toggle="modal" data-bs-target="#addUserModal">
|
||||
Add User</button>
|
||||
</div>
|
||||
<table class="table table-hover table-bordered table-condensed">
|
||||
<thead class="">
|
||||
<tr class="table-active">
|
||||
<th scope="col">Fullname</th>
|
||||
<th scope="col">Username</th>
|
||||
<th scope="col">Email</th>
|
||||
<th scope="col">Phone</th>
|
||||
<th scope="col">Position</th>
|
||||
<th scope="col">Allowed Apps</th>
|
||||
<th scope="col">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (count($items) < 1): ?>
|
||||
<tr>
|
||||
<td colspan="7">No users found</td>
|
||||
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($items as $row): ?>
|
||||
<?php $ua_id = $row['ua_id']; ?>
|
||||
<tr>
|
||||
<td><?php echo $row['full_name'] ?></td>
|
||||
<td><?php echo $row['username'] ?></td>
|
||||
<td><?php echo $row['email'] ?></td>
|
||||
<td><?php echo $row['phone'] ?></td>
|
||||
<td><?php echo $row['ua_position'] ?></td>
|
||||
<td><?php echo $row['allowed_apps'] ?></td>
|
||||
<td>
|
||||
@csrf
|
||||
<input type="hidden" class="userIdinput" value="<?php echo $row['user_id'] ?>" name="userId">
|
||||
|
||||
<!-- <a href="" data-bs-toggle="modal" data-bs-target="#viewUserModal" ><img src="{{ url('public/assets/libs/bootstrap-icons/eye.svg') }}" alt="view icon" width="16" height="16"></a> -->
|
||||
<a href="" class="editUserBtn" data-bs-toggle="modal" data-bs-target="#editUserModal"><img src="{{ url('public/assets/libs/bootstrap-icons/pencil-square.svg') }}" alt="edit icon" width="16" height="16"></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
{{ $items->links() }}
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<footer class="py-5">
|
||||
<div class="row">
|
||||
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@section('page-js')
|
||||
<script src="{{ url('public/assets/libs/select2/dist/js/select2.full.min.js') }}" type="text/javascript" ></script>
|
||||
<script src="{{ url('public/assets/js/usermgt.js') }}" type="text/javascript" ></script>
|
||||
|
||||
|
||||
|
||||
@endsection
|
||||
@ -43,7 +43,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<label for="processingFee" class="form-label fw-bold text-primary">Processing Fee *</label>
|
||||
<label for="processingFee" class="form-label fw-bold text-primary">Permit Fee *</label>
|
||||
<input type="text" name="processing_fees" id="processingFee" class="form-control">
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
|
||||
@ -23,6 +23,8 @@ Auth::routes([
|
||||
Route::get('/view-pdf/{filename}', [App\Http\Controllers\PermitsController::class, 'viewPdf'])->name('view.pdf');
|
||||
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
|
||||
|
||||
Route::get('/test', [App\Http\Controllers\AdminController::class, 'indexNew'])->name('test');
|
||||
|
||||
Route::get('/sendsms', [App\Http\Controllers\UtilityController::class, 'sendSms'])->name('sendsms');
|
||||
|
||||
Route::get('/user-login', [App\Http\Controllers\UserloginController::class, 'index']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user