I’m developing a Laravel app, and have setup a login page, but I’m trying to figure out why my login form isn’t posting.
<form role="form" method="post" action="{{ route('login.perform') }}">
<div class="form-group">
<label class="form-control-label">Email address</label>
@if ($errors->has('username'))
<span class="text-danger text-left">{{ $errors->first('username') }}</span>
@endif
<div class="input-group input-group-merge">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<input type="email" class="form-control" id="input-email" placeholder="[email protected]">
</div>
</div>
<div class="form-group mb-4">
<div class="d-flex align-items-center justify-content-between">
<div>
<label class="form-control-label">Password</label>
@if ($errors->has('password'))
<span class="text-danger text-left">{{ $errors->first('password') }}</span>
@endif
</div>
<div class="mb-2">
<a href="#!" class="small text-muted text-underline--dashed border-primary">Lost password?</a>
</div>
</div>
<div class="input-group input-group-merge">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="password" class="form-control" id="input-password" placeholder="Password">
<div class="input-group-append">
<span class="input-group-text">
<a href="#" data-toggle="password-text" data-target="#input-password">
<i class="fas fa-eye"></i>
</a>
</span>
</div>
</div>
</div>
<div class="mt-4">
<button type="button" class="btn btn-sm btn-primary btn-icon rounded-pill">
<span class="btn-inner--text">Sign in</span>
<span class="btn-inner--icon"><i class="fas fa-long-arrow-alt-right"></i></span>
</button>
</div>
</form>
This is the controller that handles the login request.
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppHttpRequestsLoginRequest;
use IlluminateSupportFacadesAuth;
class LoginController extends Controller
{
/**
* Display login page.
*
* @return Renderable
*/
public function show()
{
return view('auth.login');
}
/**
* Handle account login request
*
* @param LoginRequest $request
*
* @return IlluminateHttpResponse
*/
public function login(LoginRequest $request)
{
$credentials = $request->getCredentials();
if(!Auth::validate($credentials)):
return redirect()->to('login')
->withErrors(trans('auth.failed'));
endif;
$user = Auth::getProvider()->retrieveByCredentials($credentials);
Auth::login($user);
return $this->authenticated($request, $user);
}
/**
* Handle response after user authenticated
*
* @param Request $request
* @param Auth $user
*
* @return IlluminateHttpResponse
*/
protected function authenticated(Request $request, $user)
{
return redirect()->intended();
}
}
This is the web.php route.
<?php
use IlluminateSupportFacadesRoute;
use AppHttpControllersHomeController;
use AppHttpControllersTeacherController;
use AppHttpControllersUserController;
use AppHttpControllersAuthRegisterController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group that
| contains the "web" middleware group. Now create something great!
|
*/
Route::group(['namespace' => 'AppHttpControllers'], function()
{
/**
* Home Routes
*/
Route::get('/', 'HomeController@welcome')->name('welcome');
Route::group(['middleware' => ['guest']], function() {
/**
* Register Routes
*/
Route::get('/register', 'RegisterController@show')->name('register.show');
Route::post('/register', 'RegisterController@register')->name('register.perform');
/**
* Login Routes
*/
Route::get('/login', 'LoginController@show')->name('login.show');
Route::post('/login', 'LoginController@login')->name('login.perform');
});
Route::group(['middleware' => ['auth']], function() {
/**
* Logout Routes
*/
Route::get('/logout', 'LogoutController@perform')->name('logout.perform');
});
});
The database is setup, migrated and is appearing in phpMyAdmin, routes controllers and requests are all setup correctly to my understanding.
Any help is appreciated, cheers.
3
Answers
The reason why the form can’t submit is that you don’t have submit button, add the
type="submit"
to the<button>
will resolve the issue:I read the comments, and you said the form is loaded but does not send any data. Please show how you get data in the controller, and the route also, that will help another find out the problem.
csrf is missing in your form
Try this
The reason why the form can’t submit is that you don’t have submit button, add the type="submit" to the will resolve the issue:
and csrf is missing in your form
Try this