Authenticating: Manually Authenticating Users
<?php
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
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
Accessing Specific Guard Instances
Allows you to manage authentication for separate parts of your application using entirely separate authenticatable models or user tables.
Logging Out
Remembering Users
Other Authentication Methods
Related concepts
- Manually Authenticating Users: Attempt method
- Manually Authenticating Users: Attempt method
- Manually Authenticating Users: Intended method
- Manually Authenticating Users: Specifying Additional Conditions
- Manually Authenticating Users: Accessing Specific Guard Instances
- Manually Authenticating Users: Logging Out
- Manually Authenticating Users: Remembering Users
- Manually Authenticating Users: Other Authentication Methods