add: Seperate dashboards for all types of users
This commit is contained in:
25
app/Http/Controllers/AdminController.php
Normal file
25
app/Http/Controllers/AdminController.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class AdminController extends Controller
|
||||||
|
{
|
||||||
|
// Admin dashboard (optional)
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return view('admin.dashboard');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Http/Controllers/CoordinatorController.php
Normal file
24
app/Http/Controllers/CoordinatorController.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class CoordinatorController extends Controller
|
||||||
|
{
|
||||||
|
// Coordinator dashboard (optional)
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return view('coordinator.dashboard');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/Http/Controllers/FacultyController.php
Normal file
39
app/Http/Controllers/FacultyController.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class FacultyController extends Controller
|
||||||
|
{
|
||||||
|
// Faculty dashboard (optional)
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return view('faculty.dashboard');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Faculty response form
|
||||||
|
public function responseForm()
|
||||||
|
{
|
||||||
|
// Logic to show the response form
|
||||||
|
return view('faculty.response-form');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle form submission from faculty
|
||||||
|
public function submitResponse(Request $request)
|
||||||
|
{
|
||||||
|
// Validate and handle the form submission
|
||||||
|
$validated = $request->validate([
|
||||||
|
'response' => 'required|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Save the response, perhaps to a 'responses' table
|
||||||
|
// Response::create([
|
||||||
|
// 'faculty_id' => auth()->user()->id,
|
||||||
|
// 'response' => $validated['response'],
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// Redirect or return a success message
|
||||||
|
return redirect()->route('faculty.dashboard')->with('status', 'Response submitted successfully');
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Http/Middleware/CheckRole.php
Normal file
25
app/Http/Middleware/CheckRole.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class CheckRole
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, Closure $next, $role)
|
||||||
|
{
|
||||||
|
if (Auth::check() && Auth::user()->role->name === $role) {
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
abort(403, 'Unauthorized access.');
|
||||||
|
}
|
||||||
|
}
|
||||||
23
resources/views/admin/dashboard.blade.php
Normal file
23
resources/views/admin/dashboard.blade.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('header')
|
||||||
|
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||||
|
Admin Dashboard
|
||||||
|
</h2>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||||
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||||
|
<div class="p-6 text-gray-900">
|
||||||
|
Welcome, Admin! Here you can manage roles, users, and departments.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-6">
|
||||||
|
<a href="{{ route('roles.index') }}" class="text-blue-500 underline">Manage Roles</a><br>
|
||||||
|
<a href="{{ route('departments.index') }}" class="text-blue-500 underline">Manage Departments</a><br>
|
||||||
|
<a href="{{ route('users.index') }}" class="text-blue-500 underline">Manage Users</a><br>
|
||||||
|
<a href="{{ route('profile.edit') }}" class="text-blue-500 underline">Edit Profile</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
0
resources/views/admin/responses.blade.php
Normal file
0
resources/views/admin/responses.blade.php
Normal file
22
resources/views/coordinator/dashboard.blade.php
Normal file
22
resources/views/coordinator/dashboard.blade.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('header')
|
||||||
|
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||||
|
Coordinator Dashboard
|
||||||
|
</h2>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||||
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||||
|
<div class="p-6 text-gray-900">
|
||||||
|
Welcome, Coordinator! Manage department-related tasks here.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-6">
|
||||||
|
<a href="{{ route('departments.index') }}" class="text-blue-500 underline">View Departments</a><br>
|
||||||
|
<a href="{{ route('users.index') }}" class="text-blue-500 underline">View Faculty</a><br>
|
||||||
|
<a href="{{ route('profile.edit') }}" class="text-blue-500 underline">Edit Profile</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
0
resources/views/coordinator/responses.blade.php
Normal file
0
resources/views/coordinator/responses.blade.php
Normal file
20
resources/views/faculty/dashboard.blade.php
Normal file
20
resources/views/faculty/dashboard.blade.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('header')
|
||||||
|
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||||
|
Faculty Dashboard
|
||||||
|
</h2>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="max-w-7xl mx-auto pt-3 sm:px-6 lg:px-8">
|
||||||
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||||
|
<div class="p-6 text-gray-900">
|
||||||
|
Welcome, Faculty! Manage your tasks and profile here.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-6">
|
||||||
|
<a href="{{ route('profile.edit') }}" class="text-blue-500 underline">Edit Profile</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
0
resources/views/faculty/response-form.blade.php
Normal file
0
resources/views/faculty/response-form.blade.php
Normal file
@@ -19,17 +19,17 @@
|
|||||||
@include('layouts.navigation')
|
@include('layouts.navigation')
|
||||||
|
|
||||||
<!-- Page Heading -->
|
<!-- Page Heading -->
|
||||||
@isset($header)
|
@hasSection('header')
|
||||||
<header class="bg-white shadow">
|
<header class="bg-white shadow">
|
||||||
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
|
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
|
||||||
{{ $header }}
|
@yield('header')
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@endisset
|
@endif
|
||||||
|
|
||||||
<!-- Page Content -->
|
<!-- Page Content -->
|
||||||
<main>
|
<main>
|
||||||
{{ $slot }}
|
@yield('content')
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -15,6 +15,28 @@
|
|||||||
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
|
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
|
||||||
{{ __('Dashboard') }}
|
{{ __('Dashboard') }}
|
||||||
</x-nav-link>
|
</x-nav-link>
|
||||||
|
|
||||||
|
<!-- <x-nav-link :href="route('admin.responses')" :active="request()->routeIs('admin.responses')">
|
||||||
|
{{ __('View Form Responses') }}
|
||||||
|
</x-nav-link> -->
|
||||||
|
<!-- Role-specific Links -->
|
||||||
|
@can('isAdmin')
|
||||||
|
<x-nav-link :href="route('admin.responses')" :active="request()->routeIs('admin.responses')">
|
||||||
|
{{ __('View Form Responses') }}
|
||||||
|
</x-nav-link>
|
||||||
|
@endcan
|
||||||
|
|
||||||
|
@can('isCoordinator')
|
||||||
|
<x-nav-link :href="route('coordinator.responses')" :active="request()->routeIs('coordinator.responses')">
|
||||||
|
{{ __('View Form Responses') }}
|
||||||
|
</x-nav-link>
|
||||||
|
@endcan
|
||||||
|
|
||||||
|
@can('isFaculty')
|
||||||
|
<x-nav-link :href="route('faculty.responseForm')" :active="request()->routeIs('faculty.responseForm')">
|
||||||
|
{{ __('Respond to a Form') }}
|
||||||
|
</x-nav-link>
|
||||||
|
@endcan
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -70,6 +92,25 @@
|
|||||||
<x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
|
<x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
|
||||||
{{ __('Dashboard') }}
|
{{ __('Dashboard') }}
|
||||||
</x-responsive-nav-link>
|
</x-responsive-nav-link>
|
||||||
|
|
||||||
|
<!-- Role-specific Links -->
|
||||||
|
@can('isAdmin')
|
||||||
|
<x-responsive-nav-link :href="route('admin.responses')" :active="request()->routeIs('admin.responses')">
|
||||||
|
{{ __('View Form Responses') }}
|
||||||
|
</x-responsive-nav-link>
|
||||||
|
@endcan
|
||||||
|
|
||||||
|
@can('isCoordinator')
|
||||||
|
<x-responsive-nav-link :href="route('coordinator.responses')" :active="request()->routeIs('coordinator.responses')">
|
||||||
|
{{ __('View Form Responses') }}
|
||||||
|
</x-responsive-nav-link>
|
||||||
|
@endcan
|
||||||
|
|
||||||
|
@can('isFaculty')
|
||||||
|
<x-responsive-nav-link :href="route('faculty.responseForm')" :active="request()->routeIs('faculty.responseForm')">
|
||||||
|
{{ __('Respond to a Form') }}
|
||||||
|
</x-responsive-nav-link>
|
||||||
|
@endcan
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Responsive Settings Options -->
|
<!-- Responsive Settings Options -->
|
||||||
|
|||||||
@@ -2,31 +2,65 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\ProfileController;
|
use App\Http\Controllers\ProfileController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
use App\Http\Controllers\RoleController;
|
use App\Http\Controllers\RoleController;
|
||||||
use App\Http\Controllers\DepartmentController;
|
use App\Http\Controllers\DepartmentController;
|
||||||
use App\Http\Controllers\UserController;
|
use App\Http\Controllers\UserController;
|
||||||
|
use App\Http\Controllers\AdminController;
|
||||||
|
use App\Http\Controllers\CoordinatorController;
|
||||||
|
use App\Http\Controllers\FacultyController;
|
||||||
|
use App\Http\Middleware\CheckRole;
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('welcome');
|
return view('welcome');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/dashboard', function () {
|
Route::get('/dashboard', function () {
|
||||||
return view('dashboard');
|
// Redirect users to different pages based on their role
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
if ($user->role->name === 'Admin') {
|
||||||
|
return redirect()->route('admin.dashboard');
|
||||||
|
} elseif ($user->role->name === 'Coordinator') {
|
||||||
|
return redirect()->route('coordinator.dashboard');
|
||||||
|
} elseif ($user->role->name === 'Faculty') {
|
||||||
|
return redirect()->route('faculty.dashboard');
|
||||||
|
} else {
|
||||||
|
return abort(403, 'Unauthorized');
|
||||||
|
}
|
||||||
})->middleware(['auth', 'verified'])->name('dashboard');
|
})->middleware(['auth', 'verified'])->name('dashboard');
|
||||||
|
|
||||||
|
|
||||||
Route::middleware('auth')->group(function () {
|
Route::middleware('auth')->group(function () {
|
||||||
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
|
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
|
||||||
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
|
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
|
||||||
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
|
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Admin routes
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Coordinator routes
|
||||||
|
Route::middleware(['auth', CheckRole::class . ':Coordinator'])->group(function () {
|
||||||
|
Route::get('/coordinator', [CoordinatorController::class, 'index'])->name('coordinator.dashboard');
|
||||||
|
Route::get('/coordinator/responses', [CoordinatorController::class, 'viewResponses'])->name('coordinator.responses');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Faculty routes
|
||||||
|
Route::middleware(['auth', CheckRole::class . ':Faculty'])->group(function () {
|
||||||
|
Route::get('/faculty', [FacultyController::class, 'index'])->name('faculty.dashboard');
|
||||||
|
Route::get('/faculty/response-form', [FacultyController::class, 'responseForm'])->name('faculty.responseForm');
|
||||||
|
Route::post('/faculty/submit-response', [FacultyController::class, 'submitResponse'])->name('faculty.submitResponse');
|
||||||
|
});
|
||||||
|
|
||||||
|
// API Resources
|
||||||
Route::apiResources([
|
Route::apiResources([
|
||||||
'roles' => RoleController::class,
|
'roles' => RoleController::class,
|
||||||
'departments' => DepartmentController::class,
|
'departments' => DepartmentController::class,
|
||||||
'users' => UserController::class,
|
'users' => UserController::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
require __DIR__.'/auth.php';
|
require __DIR__ . '/auth.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user