-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathProductController.php
More file actions
38 lines (30 loc) · 1.04 KB
/
ProductController.php
File metadata and controls
38 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
class ProductController extends Controller
{
public function show(Product $product): View|RedirectResponse
{
abort_unless($product->isActive(), 404);
if ($product->slug === 'nativephp-masterclass') {
return redirect()->route('course');
}
$user = Auth::user();
if (! $product->hasAccessiblePriceFor($user)) {
abort(404);
}
$bestPrice = $product->getBestPriceForUser($user);
$regularPrice = $product->getRegularPrice();
$alreadyOwned = $user && $product->isOwnedBy($user);
return view('products.show', [
'product' => $product,
'bestPrice' => $bestPrice,
'regularPrice' => $regularPrice,
'hasDiscount' => $bestPrice && $regularPrice && $bestPrice->id !== $regularPrice->id,
'alreadyOwned' => $alreadyOwned,
]);
}
}