Adding LoginForm Livewire component
This commit is contained in:
parent
d40008aafc
commit
62b32d36e7
2 changed files with 60 additions and 0 deletions
43
app/Http/Livewire/Form/LoginForm.php
Normal file
43
app/Http/Livewire/Form/LoginForm.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Form;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class LoginForm extends Component
|
||||
{
|
||||
public $username;
|
||||
|
||||
public $password;
|
||||
|
||||
protected $rules = [
|
||||
'username' => 'required|string|min:3',
|
||||
'password' => 'required|string',
|
||||
];
|
||||
|
||||
public function submit()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$cred = [
|
||||
'username' => $this->username,
|
||||
'password' => $this->password
|
||||
];
|
||||
|
||||
if (!Auth::attempt($cred)) {
|
||||
session()->flash('message', __('auth.failed'));
|
||||
return;
|
||||
}
|
||||
|
||||
return redirect()->intended('/admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the setup page
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('form.login');
|
||||
}
|
||||
}
|
||||
17
resources/views/form/login.blade.php
Normal file
17
resources/views/form/login.blade.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<form class="space-y-4" wire:submit.prevent="submit">
|
||||
@if (Session::has('message'))
|
||||
<p class="text-center text-red-400">{{ Session::get('message') }}</p>
|
||||
@endif
|
||||
|
||||
<div>
|
||||
<x-ignite-label class="sr-only" for="username">Username</x-ignite-label>
|
||||
<x-ignite-input name="username" wire:model="username" placeholder="Username" class="" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="sr-only" for="password">Password</label>
|
||||
<x-ignite-input name="password" wire:model="password" type="password" placeholder="Password" />
|
||||
</div>
|
||||
|
||||
<x-button element="input" wire:click="submit" class="w-full" type="info" value="Login" />
|
||||
</form>
|
||||
Loading…
Add table
Add a link
Reference in a new issue