Created
September 2, 2022 15:28
-
-
Save NandoKstroNet/62a3aafb791a794dab84226e37659494 to your computer and use it in GitHub Desktop.
Componente Restaurant - Laravel Tenancy Multi Database em https://codeexperts.com.br
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
<div> | |
<x-slot name="header">Meu Restaurante</x-slot> | |
@if(session()->has('success')) | |
<div class="w-full px-2 py-4 border border-green-900 bg-green-400 text-green-900 rounded mb-10"> | |
{{session('success')}} | |
</div> | |
@endif | |
<form> | |
<div class="w-full mb-8"> | |
<label>Nome Restaurante</label> | |
<input type="text" class="w-full rounded mt-2 @error('restaurant.restaurant') border-red-700 @enderror" wire:model="restaurant.restaurant"> | |
@error('restaurant.restaurant') | |
<strong class="block mt-4 text-red-700 font-bold">{{$message}}</strong> | |
@enderror | |
</div> | |
<div class="w-full mb-8"> | |
<label>Descrição</label> | |
<input type="text" class="w-full rounded mt-2 @error('restaurant.description') border-red-700 @enderror" wire:model="restaurant.description"> | |
@error('restaurant.description') | |
<strong class="block mt-4 text-red-700 font-bold">{{$message}}</strong> | |
@enderror | |
</div> | |
<div class="w-full flex justify-between gap-2 mb-8"> | |
<div class="w-1/2"> | |
<label>Telefone Fixo</label> | |
<input type="text" class="w-full rounded mt-2 @error('restaurant.phone') border-red-700 @enderror" wire:model="restaurant.phone"> | |
@error('restaurant.phone') | |
<strong class="block mt-4 text-red-700 font-bold">{{$message}}</strong> | |
@enderror | |
</div> | |
<div class="w-1/2"> | |
<label>Whatsapp</label> | |
<input type="text" class="w-full rounded mt-2 @error('restaurant.whatsapp') border-red-700 @enderror" wire:model="restaurant.whatsapp"> | |
@error('restaurant.whatsapp') | |
<strong class="block mt-4 text-red-700 font-bold">{{$message}}</strong> | |
@enderror | |
</div> | |
</div> | |
<button | |
wire:click.prevent="saveRestaurant" | |
class="px-4 py-2 text-white font-bold text-xl rounded bg-green-700 border border-green-900 hover:bg-green-500 | |
transition duration-300 ease-in-out"> | |
Salvar | |
</button> | |
</form> | |
</div> |
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\Tenants; | |
use Livewire\Component; | |
use App\Models\Tenant\Restaurant as RestaurantModel; | |
class Restaurant extends Component | |
{ | |
public ?RestaurantModel $restaurant; | |
protected $rules = [ | |
'restaurant.restaurant' => 'required|max:255', | |
'restaurant.description' => 'required|max:255', | |
'restaurant.phone' => 'required|max:20', | |
'restaurant.whatsapp' => 'required|max:20', | |
]; | |
public function mount(RestaurantModel $restaurant) | |
{ | |
$this->restaurant = $restaurant->first() ?: $restaurant; | |
} | |
public function saveRestaurant() | |
{ | |
$this->validate(); | |
$this->restaurant->save(); | |
session()->flash('success', 'Restaurante Salvo com Sucesso!'); | |
} | |
public function render() | |
{ | |
return view('livewire.tenants.restaurant'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment