Hi, You can override the built-in authorization and registration methods if you create them in your AuthController (App\Http\Controllers\Auth\AuthController.php). You can find them in AuthenticatesAndRegistersUsers.php (trait). Example: in your AuthController create custom postLogin method
public function postLogin(Request $request)
{
//pass through validation rules
$this->validate($request, ['email' => 'required', 'password' => 'required']);
$credentials = [
'email' => trim($request->get('username')),
'password' => trim($request->get('password'))
];
$remember = $request->has('remember');
//log in the user
if ($this->auth->attempt($credentials, $remember) {
return redirect()->intended('/');
}
//show error if invalid data entered
return redirect()->back()->withErrors('Login/Pass do not match')->withInput();
}
Hi! thanks for your response. generally I get the idea but now another error occured:
ReflectionException in RouteDependencyResolverTrait.php line 53: Class App\Http\Controllers\Auth\Request does not exist
I suppose I have to load that via use or adjust the namespace - I tried some back and forth but none worked. Here's the whole file now:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller {
use AuthenticatesAndRegistersUsers;
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;
$this->middleware('guest', ['except' => 'getLogout']);
}
//protected $redirectPath = '/dashboard';
public function postLogin(Request $request)
{
//pass through validation rules
$this->validate($request, ['username' => 'required', 'password' => 'required']);
$credentials = [
'username' => trim($request->get('username')),
'password' => trim($request->get('password'))
];
$remember = $request->has('remember');
//log in the user
if ($this->auth->attempt($credentials, $remember)) {
return redirect()->intended('/');
}
//show error if invalid data entered
return redirect()->back()->withErrors('Login/Pass do not match')->withInput();
}
}
I slightly adjusted it to actually use the username field from my edited login-form:
<input type="username" class="form-control" name="username" value="{{ old('username') }}">
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community