Created
May 1, 2023 12:41
-
-
Save mansha99/84c35d45e01c0c6a5f0840eac6b34933 to your computer and use it in GitHub Desktop.
Simple Livewire Component : App\Http\Livewire\Inventors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Livewire; | |
use Livewire\Component; | |
class Inventors extends Component | |
{ | |
//properties | |
public $inventor; | |
public $invention; | |
public $list; | |
//lifecycle method | |
public function mount() | |
{ | |
$this->list = [ | |
'Aeroplane' => 'Wright brothers', | |
'Computer' => 'Charles Babbage', | |
'Fountain Pen' => 'LE. Waterman', | |
'Microscope' => 'Z. Jansen', | |
'Refrigerator' => 'J . Harrison and A. Catlin', | |
'Typewriter' => 'C. Sholes' | |
]; | |
$this->fill([ | |
'invention'=>'Aeroplane', | |
'inventor' => $this->list['Aeroplane'] | |
]); | |
} | |
//updated<PropertyName> gets fired when property changes | |
public function updatedInvention() | |
{ | |
$this->inventor = $this->list[$this->invention]; | |
} | |
//connects Component to its view | |
public function render() | |
{ | |
return view('livewire.inventors'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment