Created
July 29, 2019 02:18
-
-
Save brandonpittman/fbe38d15e5067edc9938155c9bf5f9b2 to your computer and use it in GitHub Desktop.
Livewire Counter component
This file contains 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
<div class="flex flex-col items-center justify-center"> | |
<div> | |
<button wire:click="increment" class="bg-green-500 btn">+</button> | |
<button wire:click="decrement" class="bg-red-500 btn">−</button> | |
<span class="font-bold ml-4" wire:transition.fade>{{ $count }}</span> | |
</div> | |
<div class="mt-16 w-1/2 flex items-center"> | |
<button wire:click="toggle" class="btn bg-purple-500">Show Secret</button> | |
@if($isOpen) | |
<span class="ml-4 font-semibold" wire:transition.fade>This was hidden, but now it's shown.</span> | |
@endif | |
</div> | |
</div> |
This file contains 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 Counter extends Component | |
{ | |
public $count = 0; | |
public $isOpen = false; | |
public function render() | |
{ | |
return view('livewire.counter'); | |
} | |
public function increment() | |
{ | |
$this->count++; | |
} | |
public function decrement() | |
{ | |
$this->count > 0 && $this->count--; | |
} | |
public function toggle() | |
{ | |
$this->isOpen = !$this->isOpen; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment