Now that we show results after quiz was taken, let's show results for a user from all their taken quizzes.
First, we'll add a new method to the ResultController
.
app/Http/Controllers/ResultController.php:
class ResultController extends Controller{ public function index(): View { $results = Test::with('quiz')->withCount('questions')->where('user_id', auth()->id())->paginate(); return view('front.results.index', $results); } // ...}
Add the route.
routes/web.php:
// ...Route::middleware('auth')->group(function () { Route::get('results', [ResultController::class, 'index'])->name('results.index'); // ...});// ...
Of course, we need to add link to the navigation. But it needs to be wrapped in @auth
directive...