Skip to content

Instantly share code, notes, and snippets.

@putheakhem
Created March 3, 2025 10:00
Show Gist options
  • Save putheakhem/40d19913296a463cbb53bcc1715a4d5c to your computer and use it in GitHub Desktop.
Save putheakhem/40d19913296a463cbb53bcc1715a4d5c to your computer and use it in GitHub Desktop.
# Homework Lab: Implementing Laravel Blade Layout

Objective

In this lab, you will learn how to create and use Laravel Blade layouts to structure your application efficiently. The key tasks include:

  • Creating a Blade layout template
  • Using Blade sections and components
  • Extending the layout in child views
  • Rendering dynamic content in views

Tasks

1. Create a Blade Layout Template

  • Create a layouts folder inside resources/views/.
  • Inside the folder, create a main.blade.php file.
  • Define the basic structure including @yield and @section directives.

2. Create a Child View Using the Layout

  • Create a new Blade file (e.g., home.blade.php).
  • Extend main.blade.php using @extends and @section.
  • Add sample content for the homepage.

3. Use Blade Components and Partials

  • Create a Blade partial for reusable elements (e.g., header, footer).
  • Use @include to include these partials inside the layout.
  • Create a Blade component for buttons or cards.

4. Pass Data to Views

  • Modify a controller to fetch sample data from the database.
  • Pass the data to the Blade view using compact() or with().
  • Display the data dynamically inside the child view using {{ }} syntax.

5. Define Routes and Render Views

  • Create a new route for the homepage in web.php.
  • Return the home.blade.php view from a controller or directly in the route.
  • Test the page in the browser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment