Authenticating: Manually Authenticating Users


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
     * Handle an authentication attempt.
     * @param  \Illuminate\Http\Request $request
     * @return Response
    public function authenticate(Request $request)
        $credentials = $request->only('email', 'password');

        if (Auth::attempt($credentials)) {
            // Authentication passed...
            return redirect()->intended('dashboard');

Attempt method

Accepts an array of key / value pairs as its first argument.

Attempt method

Will return true if authentication was successful.

Will keep the user authenticated indefinitely, or until they manually logout.

Intended method

Will redirect the user to the URL they were attempting to access before being intercepted by the authentication middleware.

A fallback URI may be given to this method in case the intended destination is not available.

Specifying Additional Conditions

If (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
    // The user is active, not suspended, and exists.

Accessing Specific Guard Instances

Allows you to manage authentication for separate parts of your application using entirely separate authenticatable models or user tables.

If (Auth::guard('admin')->attempt($credentials)) {

Logging Out


Remembering Users

If (Auth::attempt(['email' => $email, 'password' => $password], $remember)) {
    // The user is being remembered...
If (Auth::viaRemember()) {

Other Authentication Methods

Authenticating: Manually Authenticating Users — Structure map

Clickable & Draggable!

Authenticating: Manually Authenticating Users — Related pages: