Product view

This commit is contained in:
bad 2021-12-05 22:01:53 +01:00
parent 07849a970e
commit 931b8dea5a
5 changed files with 106 additions and 36 deletions

View File

@ -15,7 +15,7 @@ class CreateImagesTable extends Migration
{
Schema::create('images', function (Blueprint $table) {
$table->uuid("uuid")->unique()->primary;
$table->foreignUuid("product_uuid")->references("uuid")->on("products");
$table->foreignUuid("product_uuid")->nullable()->references("uuid")->on("products")->nullOnDelete();
$table->string('path')->unique();
$table->timestamps();
});

44
resources/scss/product.scss vendored Normal file
View File

@ -0,0 +1,44 @@
.product-container {
display: flex;
flex-wrap: wrap;
& > div {
width: 49%;
padding: 1em;
}
}
.product-image {
width: 100%;
}
.name-price-container {
display: flex;
justify-content: space-between;
align-items: flex-end;
}
.price-currency {
font-size: 0.85em;
opacity: 0.55;
font-weight: normal;
}
.product-commands {
&, button {
width: 100%;
}
}
.admin-menu {
display: flex;
width: 100%;
& * {
width: 100%;
}
}
.admin-menu-button {
width: 100%;
}

View File

@ -1,31 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
</style>
</head>
<body>
<div>
<p>
{{ $product }}
</p>
<form method="POST">
<button type="submit">Delete</button>
@method('DELETE')
@csrf
</form>
<form method="POST" action="{{ route("addToCart", $product) }}">
<button type="submit">Add to cart</button>
@csrf
</form>
</form>
<form method="POST" action="{{ route("removeFromCart", $product) }}">
<button type="submit">Remove from cart</button>
@csrf
</form>
</div>
</body>
</html>
@push('head')
<link rel="stylesheet" href="{{ mix("css/product.css") }}">
@endpush
@extends('layouts.app')
@section('title', $product->name)
@push('head')
<link rel="stylesheet" href="{{ mix("css/login.css") }}">
@endpush
@section('main')
<div class="product-container">
<div class="product-container-left">
<img class="product-image" src="@if(isset($product->images[0])) {{ $product->images[0]->URL() }} @else {{ asset("test.txt") }} @endif">
<div class="name-price-container">
<h2 class="product-name"> {{ $product->name }} </h2>
<h3>{{ ($product->price) }}<span class="price-currency"></span></h3>
</div>
<div class="product-commands">
@auth
@if(!Auth::user()->cart()->find($product))
<form method="POST" action="{{ route("addToCart", $product) }}">
<button type="submit">Add to cart</button>
@csrf
</form>
@else
<form method="POST" action="{{ route("removeFromCart", $product) }}">
<button type="submit">Remove from cart</button>
@csrf
</form>
@endif
@if(Auth::user()->isAdmin())
<div class="admin-menu">
<a href="{{ route("product.edit", $product) }}">
<button class="admin-menu-button">Edit</button>
</a>
<form method="POST">
<button class="admin-menu-button" type="submit">Delete</button>
@method('DELETE')
@csrf
</form>
</div>
@endif
@endauth
</div>
</div>
<div>
<p>
{{ $product->description }}
</p>
</div>
</div>
@endsection()

View File

@ -18,11 +18,9 @@
</div>
<form action="{{ route("removeFromCart", $product) }}" method="post">
@csrf
<button type="submit"> Remove from cart </a>
<button type="submit"> Remove from cart </button>
</form>
@endforeach()
</div>
</div>
@endsection()
</body>
</html>

5
webpack.mix.js vendored
View File

@ -17,4 +17,7 @@ mix.js("resources/js/app.js", "public/js").sass(
).sass(
"resources/scss/login.scss",
"public/css"
);
).sass(
"resources/scss/product.scss",
"public/css"
);;