Garbage commit, squash me

This commit is contained in:
bad 2021-11-24 11:34:46 +01:00
parent 7ddc4f1458
commit 08ecbe31da
14 changed files with 46 additions and 41 deletions

View file

@ -4,15 +4,8 @@ root = true
charset = utf-8 charset = utf-8
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
indent_style = space indent_style = tabs
indent_size = 4
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.md] [*.md]
trim_trailing_whitespace = false trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
[docker-compose.yml]
indent_size = 4

View file

@ -23,14 +23,16 @@ class CartController extends Controller
//return view("product/view", ["product" => $product]); //return view("product/view", ["product" => $product]);
} }
public function addToCart(Product $product) { public function addToCart(Product $product)
{
$user = Auth::user(); $user = Auth::user();
$user->cart()->syncWithoutDetaching([$product->uuid]); $user->cart()->syncWithoutDetaching([$product->uuid]);
return back(); return back();
} }
public function removeFromCart(Product $product) { public function removeFromCart(Product $product)
{
$user = Auth::user(); $user = Auth::user();
$user->cart()->detach($product); $user->cart()->detach($product);
return back(); return back();

View file

@ -7,7 +7,8 @@ use Illuminate\Http\Request;
class MainPageController extends Controller class MainPageController extends Controller
{ {
public function index() { public function index()
{
$products = Product::query()->latest()->limit(100)->get(); $products = Product::query()->latest()->limit(100)->get();
return view("index", ["products" => $products]); return view("index", ["products" => $products]);
} }

View file

@ -57,7 +57,7 @@ class OrderController extends Controller
$order = new Order($products); $order = new Order($products);
$order->user()->associate($user); $order->user()->associate($user);
$order->cost = array_reduce($products,fn ($c, $i) => $c+=$i->price,0); $order->cost = array_reduce($products, fn ($c, $i) => $c+=$i->price, 0);
return $order->save(); return $order->save();
}); });
@ -94,8 +94,8 @@ class OrderController extends Controller
$validated = $request->validate([ $validated = $request->validate([
'address' => 'string', 'address' => 'string',
]); ]);
if(isset($validated["address"])) { if (isset($validated["address"])) {
$address = $order->address()->withDefault(fn() => new Addres($validated)); $address = $order->address()->withDefault(fn () => new Addres($validated));
$address->address = $validated["address"]; $address->address = $validated["address"];
$order->save(); $order->save();
} }

View file

@ -19,7 +19,7 @@ class AdminAuth
public function handle(Request $request, Closure $next) public function handle(Request $request, Closure $next)
{ {
$user = Auth::user(); $user = Auth::user();
if($user && $user->isAdmin()) { if ($user && $user->isAdmin()) {
return $next($request); return $next($request);
} }
throw new AccessDeniedHttpException("You must be an admin to access this path"); throw new AccessDeniedHttpException("You must be an admin to access this path");

View file

@ -23,6 +23,6 @@ class Order extends Model
public function products() public function products()
{ {
return $this->belongsToMany("App\Product", "orderProduct","productId", "orderId"); return $this->belongsToMany("App\Product", "orderProduct", "productId", "orderId");
} }
} }

View file

@ -11,7 +11,8 @@ class Product extends Model
use HasUUID; use HasUUID;
public $primaryKey = "uuid"; public $primaryKey = "uuid";
public function images() { public function images()
{
return $this->hasMany(Image::class, "product_uuid", "uuid"); return $this->hasMany(Image::class, "product_uuid", "uuid");
} }

View file

@ -45,11 +45,13 @@ class User extends Authenticatable
'email_verified_at' => 'datetime', 'email_verified_at' => 'datetime',
]; ];
public function isAdmin() { public function isAdmin()
return $this->admin; {
return $this->admin;
} }
public function cart() { public function cart()
return $this->belongsToMany(Product::class, "cart_items", "userID", "productID"); {
return $this->belongsToMany(Product::class, "cart_items", "userID", "productID");
} }
} }

View file

@ -25,7 +25,7 @@ class ProductFactory extends Factory
return [ return [
'uuid' => $this->faker->unique()->uuid(), 'uuid' => $this->faker->unique()->uuid(),
'name' => $this->faker->productName(), 'name' => $this->faker->productName(),
'price' => $this->faker->numberBetween(1,32124), 'price' => $this->faker->numberBetween(1, 32124),
'description' => $this->faker->text(10000), 'description' => $this->faker->text(10000),
]; ];
} }

View file

@ -5,6 +5,12 @@
box-sizing: border-box; box-sizing: border-box;
} }
a {
color: inherit;
text-decoration: inherit;
}
body { body {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -22,10 +28,12 @@ nav, footer {
nav { nav {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between;
padding: 1em;
} }
nav .fa { nav .fa {
font-size: 2em; font-size: 4vh;
} }
main { main {

View file

@ -10,15 +10,17 @@
<body> <body>
<nav> <nav>
<i class="fa fa-hamburger"></i> <i class="fa fa-hamburger"></i>
<div>
<a href="{{ route("login") }}">Login</a>
</div>
</nav> </nav>
<main> <main>
@yield('main') @yield('main')
</main> </main>
<footer> <footer>
<h4>Copyright 2021 JA</h4> <h4>Copyright 2021 JA</h4>
</footer> </footer>
</body> </body>
</html> </html>

View file

@ -1,16 +1,11 @@
<!DOCTYPE html> @extends('layouts.app')
<html lang="en">
<head> @section('title', "Sklep")
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> @section('main')
<title>Document</title>
<style>
</style>
</head>
<body>
@if(Session::has('success')) @if(Session::has('success'))
<div class="alert alert-success"> <div class="alert alert-success">
{{Session::get('success')}} {{ Session::get('success') }}
</div> </div>
@endif @endif
<div> <div>
@ -34,3 +29,4 @@
</div> </div>
</body> </body>
</html> </html>
@endsection()