nhalink's avatar

View completed series

When I go to my profile I can see which lessons and series I've completed, but it only shows the last 50 items and I'm only interested in which series I've completed. I've been looking to see if there is such an overview but I can't seem to find it.

Can anybody tell me if there is such an overview?

0 likes
4 replies
LaryAI's avatar
Level 58

Unfortunately, without access to the Laracasts forum, I cannot provide a specific solution. However, I can suggest a general approach to solving this problem.

To create an overview of completed series, you would need to retrieve the user's completed lessons and filter them to only include series. Here's a possible solution using Laravel's Eloquent ORM:

  1. Create a new route in your Laravel application to handle the profile page. For example, in your routes/web.php file:
Route::get('/profile', 'ProfileController@index');
  1. Create a new controller called ProfileController:
php artisan make:controller ProfileController
  1. In the ProfileController, define the index method:
use App\Models\Lesson;
use App\Models\Series;
use Illuminate\Support\Facades\Auth;

public function index()
{
    $user = Auth::user();
    
    // Retrieve the user's completed lessons
    $completedLessons = $user->completedLessons()->pluck('lesson_id')->toArray();
    
    // Filter the completed lessons to only include series
    $completedSeries = Series::whereIn('id', $completedLessons)->get();
    
    return view('profile.index', compact('completedSeries'));
}
  1. In your User model, define a relationship to retrieve the completed lessons:
use App\Models\Lesson;

public function completedLessons()
{
    return $this->belongsToMany(Lesson::class, 'user_completed_lessons');
}
  1. Finally, create a view file called index.blade.php in the resources/views/profile directory to display the completed series:
<h1>Completed Series</h1>

<ul>
    @foreach ($completedSeries as $series)
        <li>{{ $series->title }}</li>
    @endforeach
</ul>

Remember to adjust the code according to your application's specific requirements and database structure.

vincent15000's avatar

I suggest you to move your post to the Feedback category, you will have more answers.

nhalink's avatar

On that page I only see a In progress section, I thought it might have a dropdown, but that just collapses the section. This would be a logical place to also have a Completed section.

Please or to participate in this conversation.