Skip to content

Commit 68fbbdc

Browse files
committed
sub category relationships fixed
1 parent a959320 commit 68fbbdc

30 files changed

+741
-34
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ GOOGLE_CALLBACK_URL=http://localhost:8000/login/google/callback
5656
GOOGLE_RECAPTCHA_KEY=
5757
GOOGLE_RECAPTCHA_SECRET=
5858

59+
GOOGLE_MAPS_KEY=
5960

6061
#PayPal Setting & API Credentials - sandbox
6162
PAYPAL_SANDBOX_API_USERNAME=

app/Http/Controllers/Admin/ProductController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public function __construct()
2828
*/
2929
public function index()
3030
{
31-
$products = Product::orderBy('created_at', 'DESC')->paginate(10);
31+
$products = Product::orderBy('created_at', 'DESC')->with('photos', 'category', 'subCategory')->paginate(10);
32+
33+
// dd(SubCategory::find(2));
3234

3335
return view('admin.products.index', compact('products'));
3436
}
@@ -131,7 +133,7 @@ public function edit(Product $product)
131133

132134
// $productSubCategory = $product->subcategory()->get();
133135

134-
dd($productSubCategory);
136+
// dd($productSubCategory);
135137
$attributes = $product->attributes()->get();
136138

137139
return view('admin.products.create', compact('product', 'categories', 'subCategories', 'attributes'));

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected function validator(array $data)
5353
'name' => ['required', 'string', 'max:255'],
5454
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
5555
'password' => ['required', 'string', 'min:8', 'confirmed'],
56+
'g-recaptcha-response' => 'required|recaptcha'
5657
]);
5758
}
5859

app/Http/Controllers/CartController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function index()
1818
{
1919
$systemInfo = SystemSetting::first();
2020

21-
$mightAlsoLike = Product::inRandomOrder()->take(4)->get();
21+
$mightAlsoLike = Product::inRandomOrder()->with('photos')->take(4)->get();
2222

2323
$discount = session()->get('coupon')['discount'] ?? 0;
2424
$newSubtotal = (Cart::subtotal() - $discount);

app/Http/Controllers/FrontendController.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ public function index()
1919
{
2020
$categories = Category::all();
2121

22-
$products = Product::orderBy('created_at', 'DESC')->paginate(8);
22+
$products = Product::orderBy('created_at', 'DESC')->with('category', 'photos')->paginate(8);
2323

2424
$slides = Slide::all();
2525

26-
$systemName = SystemSetting::first();
26+
$systemName = SystemSetting::firstOrFail();
2727

2828
return view('welcome', compact('products', 'slides', 'categories', 'systemName'));
2929
}
3030

3131
// show single product details
3232
public function show($slug)
3333
{
34-
$product = Product::where('slug', $slug)->firstOrFail();
34+
$product = Product::where('slug', $slug)->with('photos', 'attributes')->firstOrFail();
3535

3636
$singleImage = $product->photos()->get()->first();
3737

38-
$relatedProducts = $product->category->products()->inRandomOrder()->take(5)->get();
38+
$relatedProducts = $product->category->products()->with('photos')->inRandomOrder()->take(5)->get();
3939

4040
$systemName = SystemSetting::first();
4141

@@ -52,7 +52,7 @@ public function contact()
5252
{
5353
$info = SystemSetting::first();
5454

55-
$products = Product::orderBy('id', 'DESC')->take(4)->get();
55+
$products = Product::orderBy('id', 'DESC')->with('photos')->take(4)->get();
5656

5757
return view('contact', compact('info', 'products'));
5858
}
@@ -74,9 +74,9 @@ public function contactStore(Request $request)
7474
// display all categories and products
7575
public function categories()
7676
{
77-
$products = Product::orderBy('created_at', 'DESC')->paginate(12);
77+
$products = Product::orderBy('created_at', 'DESC')->with('photos')->paginate(12);
7878

79-
$category = Category::all();
79+
$category = Category::with('subcategories')->get();
8080

8181
$systemInfo = SystemSetting::first();
8282

@@ -88,9 +88,9 @@ public function category($slug)
8888
{
8989
$category = Category::where('slug', $slug)->firstOrFail();
9090

91-
$products = $category->products()->orderBy('created_at', 'DESC')->paginate(12);
91+
$products = $category->products()->orderBy('created_at', 'DESC')->with('photos')->paginate(12);
9292

93-
$categories = Category::all();
93+
$categories = Category::with('subcategories')->get();
9494

9595
return view('category', compact('category', 'categories', 'products'));
9696
}
@@ -100,19 +100,19 @@ public function subcategory($slug)
100100
{
101101
$subCategory = SubCategory::where('slug', $slug)->firstOrFail();
102102

103-
$products = $subCategory->products()->orderBy('created_at', 'DESC')->paginate(12);
103+
$products = $subCategory->products()->orderBy('created_at', 'DESC')->with('photos')->paginate(12);
104104

105-
$categories = Category::all();
105+
$categories = Category::with('subcategories')->get();
106106

107107
return view('sub-category', compact('products', 'categories', 'subCategory'));
108108
}
109109

110110
// return products on sale
111111
public function onSale()
112112
{
113-
$products = Product::where('on_sale', 1)->paginate(12);
113+
$products = Product::where('on_sale', 1)->with('photos')->paginate(12);
114114

115-
$categories = Category::all();
115+
$categories = Category::with('subcategories')->get();
116116

117117
return view('sale', compact('categories', 'products'));
118118
}

app/Http/Controllers/PaypalController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class PaypalController extends Controller
1010
{
11+
// class shared property
1112
private function checkoutData($orderId) {
1213
//get total from cart
1314
$discount = session()->get('coupon')['discount'] ?? 0;

app/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function category()
2323
return $this->belongsTo(Category::class);
2424
}
2525

26-
public function subcategory()
26+
public function subCategory()
2727
{
2828
return $this->belongsTo(SubCategory::class);
2929
}

app/Providers/AppServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Facades\View;
77
use Illuminate\Support\Facades\Schema;
88
use Illuminate\Support\ServiceProvider;
9+
use Illuminate\Support\Facades\Validator;
910

1011
class AppServiceProvider extends ServiceProvider
1112
{
@@ -26,9 +27,9 @@ public function register()
2627
*/
2728
public function boot()
2829
{
29-
// Using Closure based composers...
3030
View::share('shareSettings', SystemSetting::first());
3131

3232
Schema::defaultStringLength(191);
33+
Validator::extend('recaptcha', 'App\\Validators\\ReCaptcha@validate');
3334
}
3435
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Support\Facades\Gate;
6+
use Laravel\Telescope\IncomingEntry;
7+
use Laravel\Telescope\Telescope;
8+
use Laravel\Telescope\TelescopeApplicationServiceProvider;
9+
10+
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
11+
{
12+
/**
13+
* Register any application services.
14+
*
15+
* @return void
16+
*/
17+
public function register()
18+
{
19+
// Telescope::night();
20+
21+
$this->hideSensitiveRequestDetails();
22+
23+
Telescope::filter(function (IncomingEntry $entry) {
24+
if ($this->app->environment('local')) {
25+
return true;
26+
}
27+
28+
return $entry->isReportableException() ||
29+
$entry->isFailedRequest() ||
30+
$entry->isFailedJob() ||
31+
$entry->isScheduledTask() ||
32+
$entry->hasMonitoredTag();
33+
});
34+
}
35+
36+
/**
37+
* Prevent sensitive request details from being logged by Telescope.
38+
*
39+
* @return void
40+
*/
41+
protected function hideSensitiveRequestDetails()
42+
{
43+
if ($this->app->environment('local')) {
44+
return;
45+
}
46+
47+
Telescope::hideRequestParameters(['_token']);
48+
49+
Telescope::hideRequestHeaders([
50+
'cookie',
51+
'x-csrf-token',
52+
'x-xsrf-token',
53+
]);
54+
}
55+
56+
/**
57+
* Register the Telescope gate.
58+
*
59+
* This gate determines who can access Telescope in non-local environments.
60+
*
61+
* @return void
62+
*/
63+
protected function gate()
64+
{
65+
Gate::define('viewTelescope', function ($user) {
66+
return in_array($user->email, [
67+
//
68+
]);
69+
});
70+
}
71+
}

app/Validators/ReCaptcha.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Validators;
4+
use GuzzleHttp\Client;
5+
class ReCaptcha
6+
{
7+
public function validate($attribute, $value, $parameters, $validator)
8+
{
9+
$client = new Client;
10+
$response = $client->post(
11+
'https://www.google.com/recaptcha/api/siteverify',
12+
[
13+
'form_params' =>
14+
[
15+
'secret' => config('services.recaptcha.secret'),
16+
'response' => $value
17+
]
18+
]
19+
);
20+
$body = json_decode((string)$response->getBody());
21+
return $body->success;
22+
}
23+
}

0 commit comments

Comments
 (0)