Back to Course |
[Mini-Course] Laravel 11: Breeze with User Role Areas

Removing the Dashboard: Auto-Redirect to Student Timetable

If you have different roles, I imagine they will have their own dashboards or starting pages. So, we don't need the default dashboard page from Breeze, and I will show you how to remove it in this lesson.


Navigation Menu

First, let's remove the links from the navigation.

resources/views/layouts/navigation.blade.php:

<nav x-data="{ open: false }" class="bg-white dark:bg-gray-800 border-b border-gray-100 dark:border-gray-700">
// ...
<!-- Logo -->
<div class="shrink-0 flex items-center">
<a href="{{ route('dashboard') }}"> {{-- [tl! --] --}}
<a href="{{ route('student.timetable') }}"> {{-- [tl! ++] --}}
<x-application-logo class="block h-9 w-auto fill-current text-gray-800 dark:text-gray-200" />
</a>
</div>
 
<!-- Navigation Links -->
<div class="hidden space-x-8 sm:-my-px sm:ms-10 sm:flex">
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')"> {{-- [tl! remove:2] --}}
{{ __('Dashboard') }}
</x-nav-link>
<x-nav-link :href="route('student.timetable')" :active="request()->routeIs('student.timetable')">
{{ __('Timetable') }}
</x-nav-link>
</div>
//...
 
<!-- Responsive Navigation Menu -->
<div :class="{'block': open, 'hidden': ! open}" class="hidden sm:hidden">
<div class="pt-2 pb-3 space-y-1">
<x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')"> {{-- [tl! remove:2] --}}
{{ __('Dashboard') }}
</x-responsive-nav-link>
</div>
 
// ...
</div>
</nav>

Dashboard Route

Then, we can remove the dashboard route.

routes/web.php:

Route::get('/', function () {
return view('welcome');
});
 
Route::middleware(['auth', 'verified'])->group(function () {
Route::get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
 
Route::prefix('student')
->name('student.')
->group(function () {
Route::get('timetable', [\App\Http\Controllers\Student\TimetableController::class, 'index'])
->name('timetable');
});
});
 
Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});
 
require __DIR__ . '/auth.php';

Customize the Auto-Redirect

Laravel Breeze automatically redirects to the dashboard route after login and registration.

For now, let's change this so that after login or registration, the user is redirected to the student.timeline Route.

Later, we will introduce a method to redirect based on the user's role.

app/Http/Controllers/Auth/AuthenticatedSessionController.php:

class AuthenticatedSessionController extends Controller
{
// ...
 
public function store(LoginRequest $request): RedirectResponse
{
$request->authenticate();
 
$request->session()->regenerate();
 
return redirect()->intended(route('dashboard', absolute: false));
return redirect()->intended(route('student.timetable', absolute: false));
}
 
// ...
}

app/Http/Controllers/Auth/RegisteredUserController.php:

class RegisteredUserController extends Controller
{
// ...
 
public function store(Request $request): RedirectResponse
{
// ...
 
return redirect(route('dashboard', absolute: false));
return redirect(route('student.timetable', absolute: false));
}
}

We can also delete the resources/views/dashboard.blade.php file.

Now, if you try to log in or register, you will be redirected to the student's timetable page instead of a dashboard.