-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathIndex.php
More file actions
81 lines (69 loc) · 1.95 KB
/
Copy pathIndex.php
File metadata and controls
81 lines (69 loc) · 1.95 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace App\Livewire\Customer\Course;
use App\Models\Course;
use App\Models\LessonProgress;
use App\Models\Product;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Component;
#[Layout('components.layouts.dashboard')]
#[Title('Course')]
class Index extends Component
{
#[Computed]
public function course(): ?Course
{
return Course::where('is_published', true)
->with(['modules' => function ($query) {
$query->where('is_published', true)
->orderBy('sort_order')
->with(['lessons' => function ($query) {
$query->where('is_published', true)->orderBy('sort_order');
}]);
}])
->first();
}
#[Computed]
public function hasPurchased(): bool
{
$product = Product::where('slug', 'nativephp-masterclass')->first();
return $product && $product->isOwnedBy(auth()->user());
}
#[Computed]
public function priceIncreaseAt(): string
{
return config('services.stripe.course_price_increase_at');
}
#[Computed]
public function priceIncreased(): bool
{
return now()->gte($this->priceIncreaseAt());
}
#[Computed]
public function currentPrice(): int
{
return $this->priceIncreased() ? 299 : 199;
}
#[Computed]
public function completedLessonIds(): array
{
return LessonProgress::where('user_id', auth()->id())
->whereNotNull('completed_at')
->pluck('course_lesson_id')
->all();
}
#[Computed]
public function totalLessons(): int
{
if (! $this->course) {
return 0;
}
return $this->course->modules->sum(fn ($module) => $module->lessons->count());
}
#[Computed]
public function completedCount(): int
{
return count($this->completedLessonIds);
}
}