Feat: Yajra tables for response view
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use App\Models\Response;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
@@ -15,11 +19,22 @@ class AdminController extends Controller
|
||||
// View responses submitted by users
|
||||
public function viewResponses()
|
||||
{
|
||||
// Logic to fetch responses from the database
|
||||
// For example, you could fetch all responses from a 'responses' table
|
||||
// $responses = Response::all(); // Replace with your actual model
|
||||
|
||||
// return view('admin.responses', compact('responses'));
|
||||
return view('admin.responses');
|
||||
}
|
||||
|
||||
public function getResponses()
|
||||
{
|
||||
$responses = Response::with('user');
|
||||
|
||||
return DataTables::of($responses)
|
||||
->addColumn('user_name', function ($response) {
|
||||
return $response->user->name ?? 'Unknown';
|
||||
})
|
||||
->addColumn('action', function ($response) {
|
||||
$viewButton = $response->proof ? '<a href="' . asset('storage/' . $response->proof) . '" target="_blank" class="btn btn-sm btn-primary">View</a>' : 'No Proof';
|
||||
return $viewButton;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
"php": "^8.2",
|
||||
"laravel/breeze": "^2.3",
|
||||
"laravel/framework": "^11.31",
|
||||
"laravel/tinker": "^2.9"
|
||||
"laravel/tinker": "^2.9",
|
||||
"yajra/laravel-datatables": "11.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.23",
|
||||
|
||||
1066
composer.lock
generated
1066
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,67 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="max-w-full mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow sm:rounded-lg">
|
||||
<div class="px-4 py-5 sm:px-6">
|
||||
<h3 class="text-xl leading-6 font-semibold text-gray-900">
|
||||
All Responses
|
||||
</h3>
|
||||
</div>
|
||||
<div class="px-4 py-5 sm:px-6">
|
||||
<div class="overflow-x-auto">
|
||||
<table id="responses-table" class="table-auto w-full text-left border-collapse border border-gray-200 rounded-lg">
|
||||
<thead class="bg-gray-100">
|
||||
<tr>
|
||||
<th class="px-4 py-2 border border-gray-200">Title</th>
|
||||
<th class="px-4 py-2 border border-gray-200">Activity Type</th>
|
||||
<th class="px-4 py-2 border border-gray-200">Start Date</th>
|
||||
<th class="px-4 py-2 border border-gray-200">End Date</th>
|
||||
<th class="px-4 py-2 border border-gray-200">Faculty</th>
|
||||
<th class="px-4 py-2 border border-gray-200">Proof</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
<!-- DataTables JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.13.1/js/dataTables.bootstrap5.min.js"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var initAjaxRoute = function(route) {
|
||||
table = $("#responses-table").DataTable({
|
||||
fnDestroy: true,
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
responsive: true,
|
||||
ajax: {
|
||||
url: route,
|
||||
},
|
||||
columns: [
|
||||
{ data: 'title', name: 'title' },
|
||||
{ data: 'activity_type', name: 'activity_type' },
|
||||
{ data: 'start_date', name: 'start_date' },
|
||||
{ data: 'end_date', name: 'end_date' },
|
||||
{ data: 'user_name', name: 'user_name' },
|
||||
{ data: 'action', name: 'proof', orderable: false, searchable: false }, // View button for proof
|
||||
],
|
||||
order: [[0, 'asc']],
|
||||
});
|
||||
};
|
||||
|
||||
initAjaxRoute("{{ route('admin.responses.data') }}");
|
||||
});
|
||||
</script>
|
||||
|
||||
@endsection
|
||||
@@ -33,4 +33,5 @@
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
@yield('scripts')
|
||||
</html>
|
||||
|
||||
@@ -40,6 +40,7 @@ Route::middleware('auth')->group(function () {
|
||||
Route::middleware(['auth', CheckRole::class . ':Admin'])->group(function () {
|
||||
Route::get('/admin', [AdminController::class, 'index'])->name('admin.dashboard');
|
||||
Route::get('/admin/responses', [AdminController::class, 'viewResponses'])->name('admin.responses');
|
||||
Route::get('/admin/responses/data', [AdminController::class, 'getResponses'])->name('admin.responses.data');
|
||||
});
|
||||
|
||||
// Coordinator routes
|
||||
|
||||
Reference in New Issue
Block a user