My login in laravel isnt working properly. I've been stuck here for a long time now. This is my login controller code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class UsersController extends Controller
{
protected function dashboard(Request $request)
{
if (Auth::attempt(array('account_number'=>$request['accountnumber-login'], 'password'=> $request['txt-password']))) {
return redirect()->intended('viewdashboard');
}
}
protected function viewdashboard()
{
return view('dashboard');
}
}
..in this controller the 'account-number' is the account number column in the database and the 'password' is the password column in the database. I've done everything correctly yet it does not redirect me to the dashboard view. Please help
and this is my html form
<html>
<form action="dashboard" method="GET">
<input type="number" name="accountnumber">
<input type="password" name="password">
</form
</html>
this is my web route folder
Route::get('dashboard', function(){
return view('dashboard_view');
}
pls help, please.
You're not using the UsersController in the route.
Route::get('dashboard', 'App\Http\Controllers\UsersController@dashboard');
Also you are accessing request data the wrong way.
Use
$request->input('accountnumber');
EDIT:
And thirdly the dashboard method must be public
public function dashboard(Request $request)
You're getting values with other names that you put in your form, try this to get the values in your controller:
public function auth(Request $request)
{
if (Auth::attempt(array('account_number'=>$request->input('accountnumber'), 'password'=> $request->input('password')]))) {
return redirect()->intended('viewdashboard');
}
NOTE: the method must be public
additionally you have to either add other route to get the dashboard request or rename the route which you're pointing your form.
Route::get('auth', 'App\Http\Controllers\UsersController@auth');
update your HTML form as well.