I'm wanting to use Laravel Fortify and Livewire to create a very simple login form. I do not want to use Jetstream as it has more features that I do not need vs features I do need.
I'm using livewire throughout my app, and would like to use it for my login page to provide real time instant validation.
The problem I am encountering is I am unable to submit the form with values if I'm using wire:model on inputs.
I also can not use auth()->attempt() because it is being hijacked by Fortify.(At least, I think it is. All know is when I use it, it returns false)
How can I use livewire with fortify? I need to send the data from the livewire component to POST /login.
Here is my current set up:
FortifyServiceProvider.php
public function boot()
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
// Custom Fortify Views =============================
// Login Page
Fortify::loginView(function () {
return view('auth.login');
});
}
My auth/login.blade.php (simply calls the livewire components with the proper layout template)
<x-layouts.auth>
@livewire('auth.login')
</x-layouts.auth>
The livewire component livewire/auth/login.blade.php:
<form wire:submit.prevent="login" action="#" method="POST">
<div>
<label for="email">Email address</label>
<input wire:model="email" id="email" type="email" required autofocus>
@error('email'){{ $message }}@enderror
</div>
<div>
<label for="password">Password</label>
<input wire:model.lazy="password" id="password" type="password" required>
@error('password'){{ $message }}@enderror
</div>
<div>
<input wire:model.lazy="remember" id="remember_me" type="checkbox">
<label for="remember_me">Remember me</label>
<a href="#">Forgot your password?</a>
</div>
<div>
<button type="submit">Sign in</button>
</div>
</form>
and my Http/Livewire/Auth/Login.php file for the livewire component:
class Login extends Component
{
public $email = '';
public $password = '';
public $remember = false;
protected $rules = [
'email' => 'required|email|exists:users,email',
'password' => 'required',
];
/**
* Shows Real time validation for email field
*/
public function updatedEmail() {
$this->validate(['email' => 'email|exists:users,email']);
}
/**
* Logs user in when form is submitted
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Support\MessageBag
*/
public function login()
{
// ******* Need to submit the form to Fortify here?? ******
}
/**
* Renders the view
* @return mixed
*/
public function render()
{
return view('livewire.auth.login')
->layout('layouts.auth');
}
}