From b872a7a5dc8713964b2cc0fd7684c48702c67623 Mon Sep 17 00:00:00 2001 From: Sgy157 Date: Sun, 10 Dec 2023 15:55:25 +0000 Subject: [PATCH 1/8] Updated link to go to category filter --- WoodLess/resources/views/product-display.blade.php | 2 +- WoodLess/resources/views/reviews/load.blade.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/WoodLess/resources/views/product-display.blade.php b/WoodLess/resources/views/product-display.blade.php index 3788e379..7eedb215 100644 --- a/WoodLess/resources/views/product-display.blade.php +++ b/WoodLess/resources/views/product-display.blade.php @@ -91,7 +91,7 @@
@foreach ($categories as $category) - {{$category->category}} + {{$category->category}} @endforeach
diff --git a/WoodLess/resources/views/reviews/load.blade.php b/WoodLess/resources/views/reviews/load.blade.php index 1bf73b11..6f62e7b7 100644 --- a/WoodLess/resources/views/reviews/load.blade.php +++ b/WoodLess/resources/views/reviews/load.blade.php @@ -174,6 +174,7 @@ @endforeach + @if ($reviews->hasPages())
+ @endif \ No newline at end of file From fce2040e01a66fea5032b62bb98aa32ee0b23f32 Mon Sep 17 00:00:00 2001 From: Sgy157 Date: Sun, 10 Dec 2023 16:06:25 +0000 Subject: [PATCH 2/8] moved to folder, view is now products.show --- .../resources/views/products/show.blade.php | 276 ++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 WoodLess/resources/views/products/show.blade.php diff --git a/WoodLess/resources/views/products/show.blade.php b/WoodLess/resources/views/products/show.blade.php new file mode 100644 index 00000000..7eedb215 --- /dev/null +++ b/WoodLess/resources/views/products/show.blade.php @@ -0,0 +1,276 @@ +@extends('layouts.base') +@section('title', 'WoodLess - '. $product->title) + +@section('style') + +@endsection + +@php + if ($product->id == 1){ + //Test code to give a product a category ('1' being the first category the the category table) + //$product->categories()->attach(2); + } + /* + These variables are declared in ProductController and are used here. + + $product - A row from the 'products' table, Eloquent model (?) + $attributes - The product's attributes decoded from JSON + $categories - The product's categories stored in the pivot table 'categories_product' + $productImages - The file path of each image used for the product, stored in a String array + $reviews - Rows from the 'reviews' table that match this product's id, stored in an Eloquent model (?) array, currently paginated by 5 + $finalCost - Gets the final price, taking into account discount + */ +@endphp + +@section('content') +
+ @include('layouts.alert') +
+ + +
+
+
+

+ {{$product->title}} +

+
+
+ @foreach ($categories as $category) + {{$category->category}} + @endforeach +
+
+
+ + +
+ +
+ +
+
+

+ @if ($product->discount > 0) +
+ £{{$finalCost}} + {{$product->discount}}% Off +
+ +
+ +
Was: £{{$product->cost}}
+
+
+ @else + £{{$product->cost}} + @endif +

+
+
+ +
+ +
+ @csrf + @if ($product->amount > 0) +
+ + @php + $count=0; + @endphp + @foreach ($attributes as $attribute => $values) + @switch($attribute) + @case('colour') + + @php $i=1; @endphp + @foreach (explode(',', $values) as $value) +
+ + +
+ @endforeach + @error('attribute-colours') + + @enderror + @break + + @default +
+ +
+ @break + @endswitch + @php + $count++ + @endphp + @endforeach +
+ +
+
+ +
+
+ +
+
+ @else +
+
+ +
+
+ @endif +
+ +
+ +
+
+
+

{{$product->description}}

+
+
+ +
+ + + +
+
+
+ +
+
+
+

Similar Products

+
+ + @foreach ($similarProducts as $similarProduct) +

{{$similarProduct->title}}

+ @endforeach + +
+
+ +
+ + @include('reviews.load') +
+@endsection + From 77e8247a5403eef45b34d95022a53efa0978f3bc Mon Sep 17 00:00:00 2001 From: Sgy157 Date: Sun, 10 Dec 2023 16:06:38 +0000 Subject: [PATCH 3/8] Moved to products folder --- .../resources/views/product-display.blade.php | 276 ------------------ 1 file changed, 276 deletions(-) delete mode 100644 WoodLess/resources/views/product-display.blade.php diff --git a/WoodLess/resources/views/product-display.blade.php b/WoodLess/resources/views/product-display.blade.php deleted file mode 100644 index 7eedb215..00000000 --- a/WoodLess/resources/views/product-display.blade.php +++ /dev/null @@ -1,276 +0,0 @@ -@extends('layouts.base') -@section('title', 'WoodLess - '. $product->title) - -@section('style') - -@endsection - -@php - if ($product->id == 1){ - //Test code to give a product a category ('1' being the first category the the category table) - //$product->categories()->attach(2); - } - /* - These variables are declared in ProductController and are used here. - - $product - A row from the 'products' table, Eloquent model (?) - $attributes - The product's attributes decoded from JSON - $categories - The product's categories stored in the pivot table 'categories_product' - $productImages - The file path of each image used for the product, stored in a String array - $reviews - Rows from the 'reviews' table that match this product's id, stored in an Eloquent model (?) array, currently paginated by 5 - $finalCost - Gets the final price, taking into account discount - */ -@endphp - -@section('content') -
- @include('layouts.alert') -
- - -
-
-
-

- {{$product->title}} -

-
-
- @foreach ($categories as $category) - {{$category->category}} - @endforeach -
-
-
- - -
- -
- -
-
-

- @if ($product->discount > 0) -
- £{{$finalCost}} - {{$product->discount}}% Off -
- -
- -
Was: £{{$product->cost}}
-
-
- @else - £{{$product->cost}} - @endif -

-
-
- -
- -
- @csrf - @if ($product->amount > 0) -
- - @php - $count=0; - @endphp - @foreach ($attributes as $attribute => $values) - @switch($attribute) - @case('colour') - - @php $i=1; @endphp - @foreach (explode(',', $values) as $value) -
- - -
- @endforeach - @error('attribute-colours') - - @enderror - @break - - @default -
- -
- @break - @endswitch - @php - $count++ - @endphp - @endforeach -
- -
-
- -
-
- -
-
- @else -
-
- -
-
- @endif -
- -
- -
-
-
-

{{$product->description}}

-
-
- -
- - - -
-
-
- -
-
-
-

Similar Products

-
- - @foreach ($similarProducts as $similarProduct) -

{{$similarProduct->title}}

- @endforeach - -
-
- -
- - @include('reviews.load') -
-@endsection - From 4c8342532db0ba3c8d79bd150730722ce403370b Mon Sep 17 00:00:00 2001 From: Sgy157 Date: Sun, 10 Dec 2023 16:07:09 +0000 Subject: [PATCH 4/8] Updated view return (products.show) --- WoodLess/app/Http/Controllers/ProductController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WoodLess/app/Http/Controllers/ProductController.php b/WoodLess/app/Http/Controllers/ProductController.php index f64d6671..45f67bbc 100644 --- a/WoodLess/app/Http/Controllers/ProductController.php +++ b/WoodLess/app/Http/Controllers/ProductController.php @@ -25,7 +25,7 @@ public function show(Product $product) request('order') ?? 'desc' )->paginate(5)->withQueryString()->fragment('reviews'); - return view('product-display', [ + return view('products.show', [ 'product' => $product, //'attributes' => ["5" => 2, "3" => 2] (???), 'attributes' => json_decode($product->attributes, true), From d9e83cd869670781048df8d4fcf26f7bee11d414 Mon Sep 17 00:00:00 2001 From: Sgy157 Date: Sun, 10 Dec 2023 16:46:08 +0000 Subject: [PATCH 5/8] Made is_admin visible --- .../migrations/2014_10_12_000000_create_users_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WoodLess/database/migrations/2014_10_12_000000_create_users_table.php b/WoodLess/database/migrations/2014_10_12_000000_create_users_table.php index 360b4128..be1daa54 100644 --- a/WoodLess/database/migrations/2014_10_12_000000_create_users_table.php +++ b/WoodLess/database/migrations/2014_10_12_000000_create_users_table.php @@ -20,7 +20,7 @@ public function up(): void $table->string('password', 255); $table->string('phone_number', 15); $table->string('image', 255)->default('no-image.svg'); - $table->boolean('is_admin')->default(false)->invisible(); + $table->boolean('is_admin')->default(false); $table->rememberToken(); $table->timestamp('email_verified_at')->nullable(); $table->timestamps(); From 9818ec83974a1d3795f90e7ded8edf5808387aa8 Mon Sep 17 00:00:00 2001 From: Sgy157 Date: Sun, 10 Dec 2023 16:46:37 +0000 Subject: [PATCH 6/8] Added isAdmin, returns boolean --- WoodLess/app/Models/User.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WoodLess/app/Models/User.php b/WoodLess/app/Models/User.php index aeaf3113..060bff4f 100644 --- a/WoodLess/app/Models/User.php +++ b/WoodLess/app/Models/User.php @@ -65,4 +65,9 @@ public function basket() { return $this->hasOne(Basket::class); } + + + public function isAdmin(){ + return $this->makeVisible('is_admin')->is_admin; + } } From 9630aea5c7790a327030a35bc7578be05d4ec4c5 Mon Sep 17 00:00:00 2001 From: Sgy157 Date: Sun, 10 Dec 2023 16:46:50 +0000 Subject: [PATCH 7/8] Changed admin logic --- WoodLess/resources/views/reviews/load.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WoodLess/resources/views/reviews/load.blade.php b/WoodLess/resources/views/reviews/load.blade.php index 6f62e7b7..7bc3dc0e 100644 --- a/WoodLess/resources/views/reviews/load.blade.php +++ b/WoodLess/resources/views/reviews/load.blade.php @@ -157,7 +157,7 @@

@auth - @if ($user == auth()->user() || auth()->user()->is_admin) + @if ($user == auth()->user() || auth()->user()->isAdmin())
@csrf From 86c49c3b26caa3fab370dec8f66a0fe5659f48ba Mon Sep 17 00:00:00 2001 From: Sgy157 Date: Sun, 10 Dec 2023 17:29:56 +0000 Subject: [PATCH 8/8] Resolved potential conflict --- WoodLess/routes/web.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/WoodLess/routes/web.php b/WoodLess/routes/web.php index 21454dcb..0b765877 100644 --- a/WoodLess/routes/web.php +++ b/WoodLess/routes/web.php @@ -1,10 +1,7 @@ >>>>>> categories-page use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; use App\Http\Controllers\BasketController;