Main Application Layout
Location:resources/views/layouts/app.blade.php
The main layout defines the base HTML structure for all pages in the application.
Complete Layout Code
Layout Structure
The layout consists of several key sections:Head Section
Meta tags, title, fonts, and asset links
Navigation
Global navbar component included via x-navbar
Content Section
Dynamic content area using @yield directive
Footer
Global footer component included via x-footer
Head Section
Meta Tags
The layout includes essential meta tags for responsive design:External Resources
The layout loads external fonts and icon libraries:- Fonts
- Icons
Asset Management
The layout uses Laravel Vite for asset compilation:- CSS: Application styles from
resources/css/app.css - JavaScript: Application scripts from
resources/js/app.js
Body Structure
The body follows a three-section layout pattern:Navbar Component
The navbar is included using Blade’s component syntax (resources/views/layouts/app.blade.php:14):
- Class:
app/View/Components/Navbar.php - Template:
resources/views/components/navbar.blade.php
Content Section
The content section uses Blade’s@yield directive (resources/views/layouts/app.blade.php:15):
Footer Component
The footer is included similarly to the navbar (resources/views/layouts/app.blade.php:16):
- Class:
app/View/Components/Footer.php - Template:
resources/views/components/footer.blade.php
Template Inheritance
Extending the Layout
Child views extend the main layout using the@extends directive:
Defining Content Sections
Child views define their content using the@section directive:
Real-World Examples
Homepage Implementation
Location:resources/views/home/index.blade.php
Catalog Page Implementation
Location:resources/views/catalogos/catalogo.blade.php
Authentication Pages
Location:resources/views/auth/login.blade.php
Cart Page Implementation
Location:resources/views/carrito/carrito.blade.php
Blade Directives Reference
@extends
Specifies which layout to inherit from:@section / @endsection
Defines a content section to inject into the layout:@yield
Defines a placeholder for content in the layout:Component Tags
Include Blade components using x- syntax:Layout Flow Diagram
Content Injection Flow
- Step 1: Extend
- Step 2: Define
- Step 3: Inject
- Step 4: Render
Child view extends the layout:
Multiple Section Support
While the current layout uses a single content section, you can define multiple sections:Best Practices
Single Layout
Use one main layout for consistency across all pages
Component Reuse
Extract common elements (navbar, footer) into components
Asset Management
Use Vite for efficient asset compilation and versioning
Semantic Structure
Maintain clear, semantic HTML structure in layouts
Layout Customization
To customize the layout for specific pages:Override Meta Tags
Add Page-Specific Styles
Include Page-Specific Scripts
Creating Additional Layouts
For specialized page types, create additional layouts:- Admin Layout: For backend administration
- Guest Layout: For public pages without navigation
- Print Layout: For printable documents