-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserProgressController.php
More file actions
36 lines (30 loc) · 923 Bytes
/
UserProgressController.php
File metadata and controls
36 lines (30 loc) · 923 Bytes
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
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Lesson;
use App\Models\UserProgress;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
final class UserProgressController extends Controller
{
/**
* Mark the given lesson as completed for the authenticated user.
* Route model binding automatically finds the Lesson by its ID (default key).
*/
public function store(Request $request, Lesson $lesson): RedirectResponse
{
$user = Auth::user();
UserProgress::firstOrCreate(
[
'user_id' => $user->id,
'lesson_id' => $lesson->id,
],
[
'completed_at' => now(),
]
);
return Redirect::back()->with('success', 'Lesson marked as complete!');
}
}