// Get the default guard instance $guard = Auth::guard(); // Attempt to authenticate the user if ($guard->attempt(['email' => $email, 'password' => $password])) { // User is authenticated } else { // Incorrect login credentials }
// Define a custom provider $provider = new CustomAuthProvider(); // Create a custom guard using the custom provider Auth::extend('my-guard', function ($app, $name, array $config) use ($provider) { return new Guard($provider, $app['session.store'], $app['request']); }); // Use the custom guard to authenticate a user $guard = Auth::guard('my-guard'); if ($guard->attempt(['username' => $username, 'password' => $password])) { // User is authenticated using custom guard } else { // Incorrect login credentials }In both examples, we use the Auth facade to get a guard instance and attempt to authenticate a user using login credentials. The first example uses the default guard, while the second example creates and uses a custom guard with a custom authentication provider. Overall, the php illuminate.support.facades Auth guard is a powerful library for handling user authentication in web applications, and offers developers flexible options for customizing and securing user access.