in Laravel 8.12 I encountered a weired problem middleware routes not redirecing to login if user is not signed in
Route::group(['prefix' => 'posts', 'as' => 'posts.'], function () {
Route::get('/', [PostController::class, 'index'])->name('index');
Route::get('/{post}', [PostController::class, 'show'])->name('show');
});
Route::group(['middleware' => 'user-auth'], function () {
Route::group(['prefix' => 'posts', 'as' => 'posts.'], function () {
/************** THIS IS NOT GETTING REDIRECTED TO LOGIN if user not logged in *************/
Route::get('/create', [PostController::class, 'create'])->name('create');
Route::post('/store', [PostController::class, 'store'])->name('store');
Route::delete('/{post}/destroy', [PostController::class, 'destroy'])->name('destroy');
});
});
Following is my middleware
public function handle($request, Closure $next)
{
if (!session()->has('user_details')) {
return redirect()->route('auth.login');
}
return $next($request);
}
Has anyone faced this issue?
Got it fixed. Thank you everyone
Обсуждают сегодня