Skip to content

Instantly share code, notes, and snippets.

@mansha99
Created May 1, 2023 12:41
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/84c35d45e01c0c6a5f0840eac6b34933 to your computer and use it in GitHub Desktop.
Save mansha99/84c35d45e01c0c6a5f0840eac6b34933 to your computer and use it in GitHub Desktop.
Simple Livewire Component : App\Http\Livewire\Inventors
<?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