Last active
January 26, 2022 15:33
-
-
Save NandoKstroNet/631a474f0c77556465e3b857ef22a56c to your computer and use it in GitHub Desktop.
Tela do Carrinho das Lojas Tenancy em https://codeexperts.com.br/curso/laravel-tenancy-1
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
| <x-guest-layout> | |
| <div class="max-w-7xl mx-auto sm:px-6 lg:px-8"> | |
| <h3 class="text-2xl font-extrabold my-8"></h3> | |
| <hr> | |
| <h5 class="my-20 text-4xl text-center font-extrabold">Carrinho</h5> | |
| <hr> | |
| <div class="w-1/2 block mx-auto mt-10"> | |
| @php $total = 0; @endphp | |
| @forelse($cart as $item) | |
| <div class="mb-4 flex justify-between"> | |
| <h5 class="text-bold text-2xl mb-4">{{$item['name']}}</h5> | |
| <p>R$ {{number_format($item['price'], 2, ',', '.')}}</p> | |
| <p><a class="font-bold text-red-700" href="{{route('cart.remove',[request('subdomain'), $item['slug']])}}">Remover</a></p> | |
| @php $total += $item['price'] @endphp | |
| </div> | |
| @empty | |
| <div class="w-full border border-yellow-600 bg-yellow-100 px-4 py-2 rounded text-yellow-600 font-bold text-xl">Nenhum item encontrado...</div> | |
| @endforelse | |
| @if($cart) | |
| <div class="border-t border-gray-200 flex justify-between pt-10"> | |
| <h5 class="text-bold text-2xl mb-4">Total</h5> | |
| <p>R$ {{number_format($total, 2, ',', '.')}}</p> | |
| </div> | |
| <div class="border-t border-gray-200 flex justify-between pt-4 mt-10"> | |
| <a href="{{route('cart.cancel', request('subdomain'))}}" | |
| class="text-xl font-bold px-4 py-2 rounded bg-red-600 text-white shadow hover:bg-red-300 transition ease-in-out delay-150 uppercase">Cancelar</a> | |
| <a href="{{route('checkout.checkout', request('subdomain'))}}" | |
| class="text-xl font-bold px-4 py-2 rounded bg-green-600 text-white shadow hover:bg-green-300 transition ease-in-out delay-150 uppercase">Concluir</a> | |
| </div> | |
| @endif | |
| </div> | |
| </div> | |
| </x-guest-layout> |
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\Controllers\Front; | |
| use App\Http\Controllers\Controller; | |
| use App\Models\Store; | |
| use App\Services\CartService; | |
| use Illuminate\Http\Request; | |
| class CartController extends Controller | |
| { | |
| public function __construct(private CartService $cartService, private Store $store) | |
| { | |
| } | |
| public function index() | |
| { | |
| $cart = $this->cartService->all(); | |
| return view('front.cart', compact('cart')); | |
| } | |
| public function add($subdomain, $product) | |
| { | |
| $store = $this->store->whereSubdomain($subdomain)->first(); | |
| $product = $store->products()->whereSlug($product)->first()->toArray(); | |
| $this->cartService->add($product); | |
| return redirect()->route('front.store', $subdomain); | |
| } | |
| public function remove($subdomain, $product) | |
| { | |
| $this->cartService->remove($product); | |
| return redirect()->route('front.store', $subdomain); | |
| } | |
| public function cancel($subdomain) | |
| { | |
| $this->cartService->clear(); | |
| return redirect()->route('front.store', $subdomain); | |
| } | |
| } |
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 | |
| Route::prefix('cart')->name('cart.')->group(function(){ | |
| Route::get('/', [\App\Http\Controllers\Front\CartController::class, 'index'])->name('index'); | |
| Route::get('add/{product}', [\App\Http\Controllers\Front\CartController::class, 'add'])->name('add'); | |
| Route::get('remove/{product}', [\App\Http\Controllers\Front\CartController::class, 'remove'])->name('remove'); | |
| Route::get('cancel', [\App\Http\Controllers\Front\CartController::class, 'cancel'])->name('cancel'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment