Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel avoid logged in user to access a page

//Create the middleware if not exists
class RedirectIfAuthenticated 
{ 
    public function handle(Request $request, Closure $next, ...$guards)
    {
        $guards = empty($guards) ? [null] : $guards;

        foreach ($guards as $guard) {
            if (Auth::guard($guard)->check()) {
              	//redirect to where you want
                return redirect(url('dashboard'));
            }
        }
        return $next($request);
    }
}


//Then use the middleware in pages you don't want logged in users to access like this
Route::get('/register', [AuthController::class, 'register'])->name("register")
    ->middleware(RedirectIfAuthenticated::class);

Comment

PREVIOUS NEXT
Code Example
Php :: php mixing 2 string 
Php :: how to count no of words in a string in php without using string functions 
Php :: woocommerce change "Billing Details" text 
Php :: Using middleware auth laravel in controller constructor 
Php :: laravel blade get authenticated user email 
Php :: how to create a get route in Laravel 
Php :: php quit 
Php :: laravel bootstrap nav active 
Php :: group array php by key 
Php :: php string replace regex 
Php :: how to delete all data from table in php 
Php :: wordpress global variable not working 
Php :: remove symbolsand spaces php 
Php :: php prime numbers 
Php :: PHP str_replace — Replace all occurrences of the search string with the replacement string 
Php :: php foreach mysql result 
Php :: php multi type parameter php multi type parameter 
Php :: implode with br in php 
Php :: laravel update and insert transaction 
Php :: laravel faker title 
Php :: wp get acf category in post 
Php :: how to create a logout button in wordpress 
Php :: 24 hours date format php 
Php :: test curl php 
Php :: php array_values 
Php :: laravel created_at where date format 
Php :: remove all items of an array except the last one in php 
Php :: php delete element from array 
Php :: php number to color 
Php :: last page url in php laravel 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =