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
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
indent_style = tabs
trim_trailing_whitespace = true
[*.md]
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]);
}
public function addToCart(Product $product) {
public function addToCart(Product $product)
{
$user = Auth::user();
$user->cart()->syncWithoutDetaching([$product->uuid]);
return back();
}
public function removeFromCart(Product $product) {
public function removeFromCart(Product $product)
{
$user = Auth::user();
$user->cart()->detach($product);
return back();

View File

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

View File

@ -57,7 +57,7 @@ class OrderController extends Controller
$order = new Order($products);
$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();
});
@ -94,8 +94,8 @@ class OrderController extends Controller
$validated = $request->validate([
'address' => 'string',
]);
if(isset($validated["address"])) {
$address = $order->address()->withDefault(fn() => new Addres($validated));
if (isset($validated["address"])) {
$address = $order->address()->withDefault(fn () => new Addres($validated));
$address->address = $validated["address"];
$order->save();
}

View File

@ -19,7 +19,7 @@ class AdminAuth
public function handle(Request $request, Closure $next)
{
$user = Auth::user();
if($user && $user->isAdmin()) {
if ($user && $user->isAdmin()) {
return $next($request);
}
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()
{
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;
public $primaryKey = "uuid";
public function images() {
public function images()
{
return $this->hasMany(Image::class, "product_uuid", "uuid");
}

View File

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

View File

@ -1,7 +1,7 @@
<?php
return [
'email' => env("ADMIN_EMAIL"),
'username' => env("ADMIN_USERNAME"),
'password' => env("ADMIN_PASSWORD"),
'email' => env("ADMIN_EMAIL"),
'username' => env("ADMIN_USERNAME"),
'password' => env("ADMIN_PASSWORD"),
];

View File

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

View File

@ -20,7 +20,7 @@ class DatabaseSeeder extends Seeder
$creds = [
'email' => config('admin.email'),
'name' => config('admin.username'),
'password' => config('admin.password'),
'password' => config('admin.password'),
];
$creds["password"] = Hash::make($creds["password"]);
$user = User::create($creds);

View File

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

View File

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

View File

@ -1,16 +1,11 @@
<!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>
@extends('layouts.app')
@section('title', "Sklep")
@section('main')
@if(Session::has('success'))
<div class="alert alert-success">
{{Session::get('success')}}
{{ Session::get('success') }}
</div>
@endif
<div>
@ -34,3 +29,4 @@
</div>
</body>
</html>
@endsection()