I have a simple login and I have been unable to find the error for 2 days now. I have the required login and password in the database, but no matter what I enter in the login, I am thrown out and it says that the login or password is incorrect. Im using sqllite laravel-10 php AuthController
class AuthController extends Controller
{
public function showLoginForm()
{
return view("auth.login");
}
public function login(Request $request)
{
$data = $request->validate([
"email" => ["required", "email", "string"],
"password" => ["required"]
]);
if(auth("web")->attempt($data)) {
return redirect(route("home"));
}
return redirect(route("login"))->withErrors(["email" => "wrong data"]);
}
public function logout()
{
auth("web")->logout();
return redirect(route("login"));
}
}
config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
],
web.php
Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('/login_process', [AuthController::class, 'login'])->name('login_process');
App/Models/User.php
class User extends Authenticatable
{
use HasFactory;
protected $fillable = [
'email',
'name',
'role',
'status',
'password',
];
}
When I enter the correct data from the database, it just gives an error that the data is incorrect. i alse add admin user to the db
DB::table('users')->insert([
'email' => '[email protected]',
'name' => 'admin',
'role' => 'admin',
'password' => 'admin',
]);
i tried to find answers and use different auth methods but nothig works
["email" => wrong data"]if(auth("web")->attempt($data)) {appears to always return false. Begin your debugging here. By "debugging" you'll have to log the state. You can do this by outputting whichever state to an external file.