To reuse just the login parts of your Breeze setup on the home page for non-logged-in users, you can extract the login form into a separate Livewire component and then include that component both in the full login page and on the home page.
Here's how you can do it:
- Create a new Livewire component for the login form.
php artisan make:livewire LoginForm
- Move the login form HTML and the corresponding Livewire logic from your existing full-page component to the new
LoginFormcomponent.
Here's an example of what the LoginForm component might look like:
// app/Http/Livewire/LoginForm.php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Support\Facades\Auth;
class LoginForm extends Component
{
public $email;
public $password;
public $remember;
protected $rules = [
'email' => 'required|email',
'password' => 'required',
];
public function login()
{
$this->validate();
if (Auth::attempt(['email' => $this->email, 'password' => $this->password], $this->remember)) {
session()->regenerate();
return redirect()->intended(RouteServiceProvider::HOME);
}
$this->addError('email', trans('auth.failed'));
}
public function render()
{
return view('livewire.login-form');
}
}
- Create a new Blade view for the
LoginFormcomponent.
{{-- resources/views/livewire/login-form.blade.php --}}
<form wire:submit.prevent="login">
<!-- Email Address -->
<div>
<label for="email">Email</label>
<input wire:model="email" id="email" type="email" required autofocus>
@error('email') <span>{{ $message }}</span> @enderror
</div>
<!-- Password -->
<div>
<label for="password">Password</label>
<input wire:model="password" id="password" type="password" required>
@error('password') <span>{{ $message }}</span> @enderror
</div>
<!-- Remember Me -->
<div>
<label for="remember">
<input wire:model="remember" id="remember" type="checkbox">
Remember me
</label>
</div>
<div>
<button type="submit">Log in</button>
</div>
</form>
- Include the
LoginFormcomponent in your full login page and on the home page.
In your full login page:
{{-- Inside your full login page view --}}
<livewire:login-form />
On your home page:
{{-- On your home page view --}}
@auth
<!-- The user is already logged in, so you might show a different content -->
@else
<livewire:login-form />
@endauth
Regarding your question about potential conflicts between Breeze and Filament, they serve different purposes and should not conflict with each other. Breeze provides a simple authentication scaffolding, while Filament is an admin panel for Laravel. However, if you encounter any specific issues, you may need to address them on a case-by-case basis.
Remember to run php artisan livewire:discover after creating new Livewire components to ensure they are registered properly.