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
- Create a
layouts
folder insideresources/views/
. - Inside the folder, create a
main.blade.php
file. - Define the basic structure including
@yield
and@section
directives.
- Create a new Blade file (e.g.,
home.blade.php
). - Extend
main.blade.php
using@extends
and@section
. - Add sample content for the homepage.
- 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.
- Modify a controller to fetch sample data from the database.
- Pass the data to the Blade view using
compact()
orwith()
. - Display the data dynamically inside the child view using
{{ }}
syntax.
- 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.