Skip to content

Instantly share code, notes, and snippets.

@mansha99
Created May 13, 2023 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mansha99/f80a0b7980329c275ae1a8fb706bdd83 to your computer and use it in GitHub Desktop.
Save mansha99/f80a0b7980329c275ae1a8fb706bdd83 to your computer and use it in GitHub Desktop.
A Laravel Livewire component displaying Livewire validation in action
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Calculator extends Component
{
public $n1;
public $n2;
public $result='';
protected $rules = [
'n1' => 'required|numeric|min:1',
'n2' => 'required|numeric|min:1',
];
public function multiply()
{
$this->validate();
$this->result = $this->n1 *$this->n2;
}
public function render()
{
return view('livewire.calculator');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment