Feat: Responses table for coordinator
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\Response;
|
||||
|
||||
class CoordinatorController extends Controller
|
||||
{
|
||||
@@ -15,10 +18,49 @@ class CoordinatorController extends Controller
|
||||
// View responses submitted by users
|
||||
public function viewResponses()
|
||||
{
|
||||
// Logic to fetch responses for Coordinator
|
||||
// $responses = Response::where('department_id', auth()->user()->department_id)->get(); // Example query
|
||||
|
||||
// return view('coordinator.responses', compact('responses'));
|
||||
return view('coordinator.responses');
|
||||
}
|
||||
|
||||
|
||||
public function getResponses()
|
||||
{
|
||||
// Get the current logged-in user
|
||||
$currentUser = Auth::user();
|
||||
|
||||
// Get the department ID of the current user
|
||||
$userDepartmentId = $currentUser->department->id ?? null;
|
||||
|
||||
// Fetch the responses and filter by department_id
|
||||
$responses = Response::with('user', 'department')
|
||||
->where('department_id', $userDepartmentId); // Filter by current user's department_id
|
||||
|
||||
return DataTables::of($responses)
|
||||
->addColumn('user_name', function ($response) {
|
||||
return $response->user->name ?? 'Unknown';
|
||||
})
|
||||
->addColumn('department_name', function ($response) {
|
||||
return $response->department->name ?? 'Unknown';
|
||||
})
|
||||
->addColumn('start_date', function ($response) {
|
||||
return \Carbon\Carbon::parse($response->start_date)->format('d-m-Y');
|
||||
})
|
||||
->addColumn('start_time', function ($response) {
|
||||
return \Carbon\Carbon::parse($response->start_date)->format('h:i A');
|
||||
})
|
||||
->addColumn('end_date', function ($response) {
|
||||
return \Carbon\Carbon::parse($response->end_date)->format('d-m-Y');
|
||||
})
|
||||
->addColumn('end_time', function ($response) {
|
||||
return \Carbon\Carbon::parse($response->end_date)->format('h:i A');
|
||||
})
|
||||
->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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user