Hi, is it possible to modify how Spark logs in user? I would like to use a username instead of an email. Probably modifying Laravel\Spark\Http\Controllers\Auth\LoginController is not the answer. How to set custom redirectUrl after login?
Well, Spark uses Laravel for auth so it should work. Although, I have not tried to change it in my projects. You should be able to override the username method with
public function username()
{
return 'username';
}
It should work. The $redirecTo variable still applies. It is also in the Login Controller. I guess you could try modifying the sample project to see if it breaks anything. Just click on the button for the sample after logging in to spark site.
Hi, has anyone gotten this to work with 5.4 and Spark 4.0? I tried the method mentioned by @ejdelmonico but am getting a 'the email field is required' notice on login. Thanks
@kiogo In 5.4, you can just override the credentials method in the login controller. Fore example, here is a sample that adds an is_active requirement to login requirements.
/**
* Override the credential method for login
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function credentials(Request $request)
{
return array_merge($request->only($this->username(), 'password'),
['is_active' => 1]);
}
@ejdelmonico , thanks for that, however I can't figure out how to override the Spark login controller. The controller at app/Http/Controllers/Auth/LoginController.php does not seem to override the one at vendor/laravel/spark/src/Http/Controllers/Auth/LoginController.php
@cronix What does spark use? Need to know as I'm also trying to set up logging in with username instead of email in Spark. I've gotten the user registration part solved. I've changed the login view to accept username instead of email, but I am getting a validation error saying email is required.
Jul 8, 2017
Hi, has anyone gotten this to work with 5.4 and Spark 4.0? I tried the method mentioned by @ejdelmonico but am getting a 'the email field is required' notice on login. Thanks
Spark has its own LoginController at app\spark\src\Http\Controllers\Auth\LoginController.php so adding
public function username()
{
return 'username';
}
to app\Http\Controllers\Auth\LoginController.php will not do anything as Spark uses its own LoginController as mentioned above. To ensure proper implementation of