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) { Schema::create('images', function (Blueprint $table) {
$table->uuid("uuid")->unique()->primary; $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->string('path')->unique();
$table->timestamps(); $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> @push('head')
<html lang="en"> <link rel="stylesheet" href="{{ mix("css/product.css") }}">
<head> @endpush
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> @extends('layouts.app')
<title>Document</title>
<style> @section('title', $product->name)
</style>
</head> @push('head')
<body> <link rel="stylesheet" href="{{ mix("css/login.css") }}">
<div> @endpush
<p>
{{ $product }} @section('main')
</p> <div class="product-container">
<form method="POST"> <div class="product-container-left">
<button type="submit">Delete</button> <img class="product-image" src="@if(isset($product->images[0])) {{ $product->images[0]->URL() }} @else {{ asset("test.txt") }} @endif">
@method('DELETE') <div class="name-price-container">
@csrf <h2 class="product-name"> {{ $product->name }} </h2>
</form> <h3>{{ ($product->price) }}<span class="price-currency"></span></h3>
<form method="POST" action="{{ route("addToCart", $product) }}"> </div>
<button type="submit">Add to cart</button> <div class="product-commands">
@csrf @auth
</form> @if(!Auth::user()->cart()->find($product))
</form> <form method="POST" action="{{ route("addToCart", $product) }}">
<form method="POST" action="{{ route("removeFromCart", $product) }}"> <button type="submit">Add to cart</button>
<button type="submit">Remove from cart</button> @csrf
@csrf </form>
</form> @else
</div> <form method="POST" action="{{ route("removeFromCart", $product) }}">
</body> <button type="submit">Remove from cart</button>
</html> @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> </div>
<form action="{{ route("removeFromCart", $product) }}" method="post"> <form action="{{ route("removeFromCart", $product) }}" method="post">
@csrf @csrf
<button type="submit"> Remove from cart </a> <button type="submit"> Remove from cart </button>
</form> </form>
@endforeach() @endforeach()
</div> </div>
</div> </div>
@endsection() @endsection()
</body>
</html>

5
webpack.mix.js vendored
View File

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