Filament Nested Resources: Managing Courses and Lessons | Mohamed Said        [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com) [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles  ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

       [  ](https://github.com/EG-Mohamed)       

 [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

  [ home ](https://msaied.com)    [ articles ](https://msaied.com/articles)    Filament Nested Resources: Managing Courses and Their Lessons        On this page       1. [  Understanding Nested Resources ](#understanding-nested-resources)
2. [  Preparing the Lesson Resource ](#preparing-the-lesson-resource)
3. [  Adding an Action to the Course Resource ](#adding-an-action-to-the-course-resource)
4. [  Customizing the Create Lesson Action ](#customizing-the-create-lesson-action)
5. [  Takeaways ](#takeaways)

  ![Filament Nested Resources: Managing Courses and Their Lessons](https://cdn.msaied.com/94/7b6737a1d481f958c0407ddc5fa35fee.png)

 [  Laravel ](https://msaied.com/articles?category=laravel)  #Filament   #Laravel   #Nested Resources   #Admin Panel   #PHP  

 Filament Nested Resources: Managing Courses and Their Lessons 
===============================================================

     31 Oct 2023      2 min read    ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said  

       Table of contents

1. [  01   Understanding Nested Resources  ](#understanding-nested-resources)
2. [  02   Preparing the Lesson Resource  ](#preparing-the-lesson-resource)
3. [  03   Adding an Action to the Course Resource  ](#adding-an-action-to-the-course-resource)
4. [  04   Customizing the Create Lesson Action  ](#customizing-the-create-lesson-action)
5. [  05   Takeaways  ](#takeaways)

 Managing hierarchical data within an administration panel is a common requirement for many web applications. For Laravel developers using Filament, implementing nested resources can significantly improve the user experience by allowing direct management of related records. This tutorial demonstrates how to set up nested resources in Filament, using the example of managing Courses and their associated Lessons.

Understanding Nested Resources
------------------------------

In Laravel, nested resources refer to the relationship where one resource controller is nested within another. For instance, a Lesson is typically associated with a Course, making it a nested resource. Filament provides a straightforward way to integrate this concept into its admin panel.

Our goal is to achieve the following:

1. From the list of courses, provide a direct link to manage the lessons for each specific course.
2. The lesson management page should clearly display the parent course's title and include breadcrumbs that reflect this hierarchy.

Preparing the Lesson Resource
-----------------------------

To enable nested resource management, we need to configure the LessonResource. Several key adjustments are necessary:

- Define a new route slug: We'll set a specific slug for the LessonResource to indicate its nested nature, such as courses/lessons.
- Prevent navigation registration: Since lessons are managed within the context of a course, the LessonResource itself shouldn't appear as a top-level item in the Filament navigation.
- Modify the getEloquentQuery(): This is crucial for filtering lessons to show only those belonging to the currently selected course. We'll use the record parameter from the request.
- Adjust getPages(): We need to define custom routes for listing, creating, and editing lessons, ensuring they accept the parent record parameter.

Here's the configuration for app/Filament/Resources/LessonResource.php:

```php
