I have created a Login form called UserLogin.blade.php. And I have created a controller called UserLoginControl.php and model called login.php. Now I want to log into my system by using Username and Password which is in the database. But , after I enter Username and password and when clicking the Login button , it shows me this error -
(1/1) ErrorException
Undefined index: password
But , I have declared Username and Password in UserLoginController.php file.
How can I Fix this ??
Here is the UserLogin.blade.php ( View file ).
<!DOCTYPE html>
<html>
<head>
</head>
<body">
<form method="post" action="{{ route('UserLogin') }}">
{{ csrf_field() }}
Username : <input type="text" name="username"> <br><br>
Password : <br><input type="password" name="password" class="text"> <br><br>
<input type="submit" name="login" value="Login"> <br>
<small><a href="{{ route('first') }}">Return Home</a></small>
</form>
</center>
</body>
</html>
Here is the UserLoginController.php ( Controller file ).
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\login;
use Illuminate\Support\Facades\Auth;
class UserLoginController extends Controller
{
public function index()
{
return view('UserLogin');
}
public function login(Request $request)
{
$this->validate($request, [
'username' => 'required',
'password' => 'required'
]);
if (Auth::attempt(['username' => $request['username'], 'pw' => $request['password']])) {
return redirect('RegView');
}
return redirect('UserLogin');
}
}
Here is the login.php ( Model file ).
<?php
namespace App;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
class login extends Model implements Authenticatable
{
use \Illuminate\Auth\Authenticatable;
}
And I have written this in Auth.php file
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
'users' => [
'driver' => 'eloquent',
'model' => App\login::class,
],
Here is the Routes that I have created.
Route::any('/UserLogin', 'UserLoginController@index')->name('UserLogin');
Route::post('/UserLogin','UserLoginController@login');
Edureka please help me out with this error.
Thank You!!