CINXE.COM

Blade Templates - Laravel 11.x - The PHP Framework For Web Artisans

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Blade Templates - Laravel 11.x - The PHP Framework For Web Artisans</title> <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"> <link rel="canonical" href="https://laravel.com/docs/11.x/blade"> <!-- Primary Meta Tags --> <meta name="title" content="Laravel - The PHP Framework For Web Artisans"> <meta name="description" content="Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things."> <!-- Open Graph / Facebook --> <meta property="og:type" content="website"> <meta property="og:url" content="https://laravel.com/"> <meta property="og:title" content="Laravel - The PHP Framework For Web Artisans"> <meta property="og:description" content="Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things."> <meta property="og:image" content="https://laravel.com/img/og-image.jpg"> <!-- Twitter --> <meta property="twitter:card" content="summary_large_image"> <meta property="twitter:url" content="https://laravel.com/"> <meta property="twitter:title" content="Laravel - The PHP Framework For Web Artisans"> <meta property="twitter:description" content="Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things."> <meta property="twitter:image" content="https://laravel.com/img/og-image.jpg"> <!-- Favicon --> <link rel="apple-touch-icon" sizes="180x180" href="/img/favicon/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="32x32" href="/img/favicon/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="/img/favicon/favicon-16x16.png"> <link rel="manifest" href="/img/favicon/site.webmanifest"> <link rel="mask-icon" href="/img/favicon/safari-pinned-tab.svg" color="#ff2d20"> <link rel="shortcut icon" href="/img/favicon/favicon.ico"> <meta name="msapplication-TileColor" content="#ff2d20"> <meta name="msapplication-config" content="/img/favicon/browserconfig.xml"> <meta name="theme-color" content="#ffffff"> <meta name="color-scheme" content="light"> <link rel="preconnect" href="https://E3MIRNPJH5-dsn.algolia.net" crossorigin /> <link rel="stylesheet" href="https://use.typekit.net/ins2wgm.css"> <link rel="preload" as="style" href="https://laravel.com/build/assets/app-dc063eeb.css" /><link rel="modulepreload" href="https://laravel.com/build/assets/app-70a5a3a6.js" /><link rel="modulepreload" href="https://laravel.com/build/assets/docs-45166933.js" /><link rel="stylesheet" href="https://laravel.com/build/assets/app-dc063eeb.css" /><script type="module" src="https://laravel.com/build/assets/app-70a5a3a6.js"></script><script type="module" src="https://laravel.com/build/assets/docs-45166933.js"></script> <!-- Fathom - beautiful, simple website analytics --> <script src="https://cdn.usefathom.com/script.js" data-site="DVMEKBYF" defer></script> <!-- / Fathom --> <!-- Clearbit --> <script async src="https://tag.clearbitscripts.com/v1/pk_97d2bf69f817feb07be42fcda1460119/tags.js" referrerpolicy="strict-origin-when-cross-origin"></script> <script> const alwaysLightMode = false; </script> <script> function updateTheme() { if (!('theme' in localStorage)) { localStorage.theme = 'system'; } switch (localStorage.theme) { case 'system': if (window.matchMedia('(prefers-color-scheme: dark)').matches) { document.documentElement.classList.add('dark'); document.documentElement.setAttribute('data-theme', 'dark'); } else { document.documentElement.classList.remove('dark'); document.documentElement.setAttribute('data-theme', 'light'); } document.documentElement.setAttribute('color-theme', 'system'); break; case 'dark': document.documentElement.classList.add('dark'); document.documentElement.setAttribute('color-theme', 'dark'); document.documentElement.setAttribute('data-theme', 'dark'); break; case 'light': document.documentElement.classList.remove('dark'); document.documentElement.setAttribute('color-theme', 'light'); document.documentElement.setAttribute('data-theme', 'light'); break; } updateThemeAndSchemeColor(); } function updateThemeAndSchemeColor() { if (! alwaysLightMode) { if (document.documentElement.classList.contains('dark')) { document.querySelector('meta[name="color-scheme"]').setAttribute('content', 'dark'); document.querySelector('meta[name="theme-color"]').setAttribute('content', '#171923'); return; } document.querySelector('meta[name="color-scheme"]').setAttribute('content', 'light'); document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff'); } } updateTheme(); </script> </head> <body x-data="{ navIsOpen: false, }" class="w-full h-full font-sans antialiased text-gray-900 language-php" data-instant-intensity="0" > <a id="skip-to-content-link" href="#main-content" class="absolute bg-gray-100 px-4 py-2 top-3 left-3 text-gray-700 shadow-xl" > Skip to content </a> <div class="items-center justify-center bg-gradient-to-b from-red-500 to-red-600 p-2 text-center text-white text-sm h-9"> <template id="news-herd"> <div> <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-white" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" stroke-linecap="round" fill="none" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"/> <path d="M3 4m0 1a1 1 0 0 1 1 -1h16a1 1 0 0 1 1 1v14a1 1 0 0 1 -1 1h-16a1 1 0 0 1 -1 -1z" /> <path d="M7 8v1" /> <path d="M17 8v1" /> <path d="M12.5 4c-.654 1.486 -1.26 3.443 -1.5 9h2.5c-.19 2.867 .094 5.024 .5 7" /> <path d="M7 15.5c3.667 2 6.333 2 10 0" /> </svg> </div> <div class="mt-px ml-1"> Get started with PHP and Laravel faster than ever using <a href="https://herd.laravel.com" class="underline">Laravel Herd</a>. </div> </template> <template id="news-laracon"> <div><svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg></div> <div class="mt-px ml-1"> Join us in Dallas, TX! Tickets are now available for <a href="https://laracon.us" class="underline">Laracon US</a>. </div> </template> <template id="news-laracon-in"> <div><svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg></div> <div class="mt-px ml-1"> Let's go to India! Tickets are now available for <a href="https://laracon.in" class="underline">Laracon IN</a>. </div> </template> <template id="news-laracon-eu"> <div><svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg></div> <div class="mt-px ml-1"> Let's go to Europe! Tickets are now available for <a href="https://laracon.eu" class="underline">Laracon EU</a>. </div> </template> <template id="news-laracon-au"> <div><svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg></div> <div class="mt-px ml-1"> Let's go down under! Tickets are now available for <a href="https://laracon.au" class="underline">Laracon AU</a>. </div> </template> <template id="news-forge"> <div><svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg></div> <div class="mt-px ml-1"> Servers with PHP 8.3 are now available for provisioning via <a href="https://forge.laravel.com" class="underline">Laravel Forge</a>. </div> </template> <template id="news-vapor"> <div><svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z"></path></svg></div> <div class="mt-px ml-1"> Deploy Laravel with the infinite scale of serverless using <a href="https://vapor.laravel.com" class="underline">Laravel Vapor</a>. </div> </template> <template id="news-cloud"> <div class="mt-px ml-1"> Join the waitlist for <a href="https://cloud.laravel.com" class="underline">Laravel Cloud</a><span class="hidden md:inline">, the future of shipping</span>. </div> </template> <template id="news-nightwatch"> <div class="mt-px ml-1"> Join the waitlist for <a href="https://nightwatch.laravel.com" class="underline">Laravel Nightwatch</a><span class="hidden md:inline">, first-class monitoring designed for Laravel</span>. </div> </template> <template id="news-pulse"> <div><svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z"></path></svg></div> <div class="mt-px ml-1"> How's your health? Check your application's vital signs using <a href="https://pulse.laravel.com" class="underline">Laravel Pulse</a>. </div> </template> <template id="news-reverb"> <div> <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-white" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"/> <path d="M3.707 6.293l2.586 -2.586a1 1 0 0 1 1.414 0l5.586 5.586a1 1 0 0 1 0 1.414l-2.586 2.586a1 1 0 0 1 -1.414 0l-5.586 -5.586a1 1 0 0 1 0 -1.414z" /> <path d="M6 10l-3 3l3 3l3 -3" /> <path d="M10 6l3 -3l3 3l-3 3" /> <path d="M12 12l1.5 1.5" /> <path d="M14.5 17a2.5 2.5 0 0 0 2.5 -2.5" /> <path d="M15 21a6 6 0 0 0 6 -6" /> </svg> </div> <div class="mt-px ml-1"> Incoming transmission received. <a href="https://reverb.laravel.com" class="underline">Laravel Reverb</a> is now available! </div> </template> <template id="news-nova"> <div> <svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> <path stroke-linecap="round" stroke-linejoin="round" d="M15.59 14.37a6 6 0 01-5.84 7.38v-4.8m5.84-2.58a14.98 14.98 0 006.16-12.12A14.98 14.98 0 009.631 8.41m5.96 5.96a14.926 14.926 0 01-5.841 2.58m-.119-8.54a6 6 0 00-7.381 5.84h4.8m2.581-5.84a14.927 14.927 0 00-2.58 5.84m2.699 2.7c-.103.021-.207.041-.311.06a15.09 15.09 0 01-2.448-2.448 14.9 14.9 0 01.06-.312m-2.24 2.39a4.493 4.493 0 00-1.757 4.306 4.493 4.493 0 004.306-1.758M16.5 9a1.5 1.5 0 11-3 0 1.5 1.5 0 013 0z"></path> </svg> </div> <div class="mt-px ml-1"> Take your administration backend to another dimension with <a href="https://nova.laravel.com" class="underline">Laravel Nova</a>. </div> </template> <template id="news-careers"> <div> <svg class="w-5 h-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M20.25 14.15v4.25c0 1.094-.787 2.036-1.872 2.18-2.087.277-4.216.42-6.378.42s-4.291-.143-6.378-.42c-1.085-.144-1.872-1.086-1.872-2.18v-4.25m16.5 0a2.18 2.18 0 0 0 .75-1.661V8.706c0-1.081-.768-2.015-1.837-2.175a48.114 48.114 0 0 0-3.413-.387m4.5 8.006c-.194.165-.42.295-.673.38A23.978 23.978 0 0 1 12 15.75c-2.648 0-5.195-.429-7.577-1.22a2.016 2.016 0 0 1-.673-.38m0 0A2.18 2.18 0 0 1 3 12.489V8.706c0-1.081.768-2.015 1.837-2.175a48.111 48.111 0 0 1 3.413-.387m7.5 0V5.25A2.25 2.25 0 0 0 13.5 3h-3a2.25 2.25 0 0 0-2.25 2.25v.894m7.5 0a48.667 48.667 0 0 0-7.5 0M12 12.75h.008v.008H12v-.008Z" /> </svg> </div> <div class="mt-px ml-1"> Laravel is hiring! <a href="https://laravel.com/careers" class="underline">Help us build the future of Laravel</a>. </div> </template> </div> <script> const activeNewsTemplate = document.getElementById( 'news-'+JSON.parse('[\u0022cloud\u0022,\u0022nightwatch\u0022]')[Math.floor(Math.random() * 2)] ) activeNewsTemplate.replaceWith(activeNewsTemplate.content) </script> <div class="relative dark:bg-dark-700" id="docsScreen"> <div class="relative lg:flex lg:items-start"> <aside class="hidden fixed top-0 bottom-0 left-0 z-20 w-16 bg-gradient-to-b from-gray-100 to-white transition-all duration-300 lg:sticky lg:w-80 lg:shrink-0 lg:flex lg:flex-col lg:justify-end lg:items-end 2xl:max-w-lg 2xl:w-full dark:from-dark-800 dark:to-dark-700"> <div class="relative max-h-screen overflow-auto flex-1 flex flex-col xl:w-80"> <a href="/" class="flex items-center py-8 px-4 lg:px-8 xl:px-16"> <img class="w-8 h-8 shrink-0 transition-all duration-300 lg:w-12 lg:h-12" src="/img/logomark.min.svg" alt="Laravel" width="50" height="52" > <img src="/img/logotype.min.svg" alt="Laravel" class="hidden ml-4 lg:block" width="114" height="29" > </a> <div class="px-4 pb-10 lg:px-8 xl:px-16"> <nav id="indexed-nav" class="hidden lg:block lg:mt-4"> <div class="docs_sidebar"> <ul> <li> <h2>Prologue</h2> <ul> <li> <a href="/docs/11.x/releases">Release Notes</a> </li> <li> <a href="/docs/11.x/upgrade">Upgrade Guide</a> </li> <li> <a href="/docs/11.x/contributions">Contribution Guide</a> </li> </ul> </li> <li> <h2>Getting Started</h2> <ul> <li> <a href="/docs/11.x/installation">Installation</a> </li> <li> <a href="/docs/11.x/configuration">Configuration</a> </li> <li> <a href="/docs/11.x/structure">Directory Structure</a> </li> <li> <a href="/docs/11.x/frontend">Frontend</a> </li> <li> <a href="/docs/11.x/starter-kits">Starter Kits</a> </li> <li> <a href="/docs/11.x/deployment">Deployment</a> </li> </ul> </li> <li> <h2>Architecture Concepts</h2> <ul> <li> <a href="/docs/11.x/lifecycle">Request Lifecycle</a> </li> <li> <a href="/docs/11.x/container">Service Container</a> </li> <li> <a href="/docs/11.x/providers">Service Providers</a> </li> <li> <a href="/docs/11.x/facades">Facades</a> </li> </ul> </li> <li class="sub--on"> <h2>The Basics</h2> <ul> <li> <a href="/docs/11.x/routing">Routing</a> </li> <li> <a href="/docs/11.x/middleware">Middleware</a> </li> <li> <a href="/docs/11.x/csrf">CSRF Protection</a> </li> <li> <a href="/docs/11.x/controllers">Controllers</a> </li> <li> <a href="/docs/11.x/requests">Requests</a> </li> <li> <a href="/docs/11.x/responses">Responses</a> </li> <li> <a href="/docs/11.x/views">Views</a> </li> <li class="active"> <a href="/docs/11.x/blade">Blade Templates</a> </li> <li> <a href="/docs/11.x/vite">Asset Bundling</a> </li> <li> <a href="/docs/11.x/urls">URL Generation</a> </li> <li> <a href="/docs/11.x/session">Session</a> </li> <li> <a href="/docs/11.x/validation">Validation</a> </li> <li> <a href="/docs/11.x/errors">Error Handling</a> </li> <li> <a href="/docs/11.x/logging">Logging</a> </li> </ul> </li> <li> <h2>Digging Deeper</h2> <ul> <li> <a href="/docs/11.x/artisan">Artisan Console</a> </li> <li> <a href="/docs/11.x/broadcasting">Broadcasting</a> </li> <li> <a href="/docs/11.x/cache">Cache</a> </li> <li> <a href="/docs/11.x/collections">Collections</a> </li> <li> <a href="/docs/11.x/concurrency">Concurrency</a> </li> <li> <a href="/docs/11.x/context">Context</a> </li> <li> <a href="/docs/11.x/contracts">Contracts</a> </li> <li> <a href="/docs/11.x/events">Events</a> </li> <li> <a href="/docs/11.x/filesystem">File Storage</a> </li> <li> <a href="/docs/11.x/helpers">Helpers</a> </li> <li> <a href="/docs/11.x/http-client">HTTP Client</a> </li> <li> <a href="/docs/11.x/localization">Localization</a> </li> <li> <a href="/docs/11.x/mail">Mail</a> </li> <li> <a href="/docs/11.x/notifications">Notifications</a> </li> <li> <a href="/docs/11.x/packages">Package Development</a> </li> <li> <a href="/docs/11.x/processes">Processes</a> </li> <li> <a href="/docs/11.x/queues">Queues</a> </li> <li> <a href="/docs/11.x/rate-limiting">Rate Limiting</a> </li> <li> <a href="/docs/11.x/strings">Strings</a> </li> <li> <a href="/docs/11.x/scheduling">Task Scheduling</a> </li> </ul> </li> <li> <h2>Security</h2> <ul> <li> <a href="/docs/11.x/authentication">Authentication</a> </li> <li> <a href="/docs/11.x/authorization">Authorization</a> </li> <li> <a href="/docs/11.x/verification">Email Verification</a> </li> <li> <a href="/docs/11.x/encryption">Encryption</a> </li> <li> <a href="/docs/11.x/hashing">Hashing</a> </li> <li> <a href="/docs/11.x/passwords">Password Reset</a> </li> </ul> </li> <li> <h2>Database</h2> <ul> <li> <a href="/docs/11.x/database">Getting Started</a> </li> <li> <a href="/docs/11.x/queries">Query Builder</a> </li> <li> <a href="/docs/11.x/pagination">Pagination</a> </li> <li> <a href="/docs/11.x/migrations">Migrations</a> </li> <li> <a href="/docs/11.x/seeding">Seeding</a> </li> <li> <a href="/docs/11.x/redis">Redis</a> </li> <li> <a href="/docs/11.x/mongodb">MongoDB</a> </li> </ul> </li> <li> <h2>Eloquent ORM</h2> <ul> <li> <a href="/docs/11.x/eloquent">Getting Started</a> </li> <li> <a href="/docs/11.x/eloquent-relationships">Relationships</a> </li> <li> <a href="/docs/11.x/eloquent-collections">Collections</a> </li> <li> <a href="/docs/11.x/eloquent-mutators">Mutators / Casts</a> </li> <li> <a href="/docs/11.x/eloquent-resources">API Resources</a> </li> <li> <a href="/docs/11.x/eloquent-serialization">Serialization</a> </li> <li> <a href="/docs/11.x/eloquent-factories">Factories</a> </li> </ul> </li> <li> <h2>Testing</h2> <ul> <li> <a href="/docs/11.x/testing">Getting Started</a> </li> <li> <a href="/docs/11.x/http-tests">HTTP Tests</a> </li> <li> <a href="/docs/11.x/console-tests">Console Tests</a> </li> <li> <a href="/docs/11.x/dusk">Browser Tests</a> </li> <li> <a href="/docs/11.x/database-testing">Database</a> </li> <li> <a href="/docs/11.x/mocking">Mocking</a> </li> </ul> </li> <li> <h2>Packages</h2> <ul> <li> <a href="/docs/11.x/starter-kits#laravel-breeze">Breeze</a> </li> <li> <a href="/docs/11.x/billing">Cashier (Stripe)</a> </li> <li> <a href="/docs/11.x/cashier-paddle">Cashier (Paddle)</a> </li> <li> <a href="/docs/11.x/dusk">Dusk</a> </li> <li> <a href="/docs/11.x/envoy">Envoy</a> </li> <li> <a href="/docs/11.x/fortify">Fortify</a> </li> <li> <a href="/docs/11.x/folio">Folio</a> </li> <li> <a href="/docs/11.x/homestead">Homestead</a> </li> <li> <a href="/docs/11.x/horizon">Horizon</a> </li> <li> <a href="https://jetstream.laravel.com">Jetstream</a> </li> <li> <a href="/docs/11.x/mix">Mix</a> </li> <li> <a href="/docs/11.x/octane">Octane</a> </li> <li> <a href="/docs/11.x/passport">Passport</a> </li> <li> <a href="/docs/11.x/pennant">Pennant</a> </li> <li> <a href="/docs/11.x/pint">Pint</a> </li> <li> <a href="/docs/11.x/precognition">Precognition</a> </li> <li> <a href="/docs/11.x/prompts">Prompts</a> </li> <li> <a href="/docs/11.x/pulse">Pulse</a> </li> <li> <a href="/docs/11.x/reverb">Reverb</a> </li> <li> <a href="/docs/11.x/sail">Sail</a> </li> <li> <a href="/docs/11.x/sanctum">Sanctum</a> </li> <li> <a href="/docs/11.x/scout">Scout</a> </li> <li> <a href="/docs/11.x/socialite">Socialite</a> </li> <li> <a href="/docs/11.x/telescope">Telescope</a> </li> <li> <a href="/docs/11.x/valet">Valet</a> </li> </ul> </li> <li> <a href="/api/11.x">API Documentation</a> </li> </ul> </div> </nav> <template id="promote-forge"> <div class="mt-4 px-3 py-2 border-dashed border-gray-200 border rounded-lg text-xs leading-loose text-gray-700 lg:block dark:border-gray-400 dark:text-gray-200"> <span class="font-medium">Laravel Forge:</span> create and manage PHP 8 servers. Deploy your Laravel applications in seconds. <a class="underline text-red-600" href="https://forge.laravel.com">Sign up now!</a>. </div> </template> <template id="promote-vapor"> <div class="mt-4 px-3 py-2 border-dashed border-gray-200 border rounded-lg text-xs leading-loose text-gray-700 lg:block dark:border-gray-400 dark:text-gray-200"> <span class="font-medium">Laravel Vapor:</span> experience extreme scale on a dedicated serverless platform for Laravel. <a class="underline text-red-600" href="https://vapor.laravel.com">Sign up now!</a>. </div> </template> <template id="promote-nova"> <div class="mt-4 px-3 py-2 border-dashed border-gray-200 border rounded-lg text-xs leading-loose text-gray-700 lg:block dark:border-gray-400 dark:text-gray-200"> <span class="font-medium">Laravel Nova:</span> The next generation of Nova is <a class="underline text-red-600" href="https://nova.laravel.com">now available</a>. </div> </template> <template id="promote-pulse"> <div class="mt-4 px-3 py-2 border-dashed border-gray-200 border rounded-lg text-xs leading-loose text-gray-700 lg:block dark:border-gray-400 dark:text-gray-200"> <span class="font-medium">Laravel Pulse:</span> How's your health? Check your application's vital signs using <a href="https://pulse.laravel.com" class="underline text-red-600">Laravel Pulse</a>. </div> </template> <template id="promote-reverb"> <div class="mt-4 px-3 py-2 border-dashed border-gray-200 border rounded-lg text-xs leading-loose text-gray-700 lg:block dark:border-gray-400 dark:text-gray-200"> <span class="font-medium">Laravel Reverb:</span> You can easily build dynamic, real-time Laravel applications using WebSockets. <a href="https://reverb.laravel.com" class="underline text-red-600">Laravel Reverb</a> is now available! </div> </template> <script> const activePromotionTemplate = document.getElementById( 'promote-'+JSON.parse('[\u0022forge\u0022,\u0022vapor\u0022,\u0022nova\u0022,\u0022pulse\u0022,\u0022reverb\u0022]')[Math.floor(Math.random() * 5)] ) activePromotionTemplate.replaceWith(activePromotionTemplate.content) </script> </div> </div> </aside> <header class="lg:hidden" @keydown.window.escape="navIsOpen = false" @click.away="navIsOpen = false" > <div class="relative mx-auto w-full py-10 bg-white transition duration-200 dark:bg-dark-700"> <div class="mx-auto px-8 sm:px-16 flex items-center justify-between"> <a href="/" class="flex items-center"> <img class="" src="/img/logomark.min.svg" alt="Laravel" width="50" height="52"> <img class="hidden ml-5 sm:block" src="/img/logotype.min.svg" alt="Laravel" width="114" height="29"> </a> <div class="flex-1 flex items-center justify-end"> <button id="header__sun" onclick="toSystemMode()" title="Switch to system theme" class="relative w-10 h-10 focus:outline-none focus:shadow-outline text-gray-500"> <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-sun" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <circle cx="12" cy="12" r="4"></circle> <path d="M3 12h1m8 -9v1m8 8h1m-9 8v1m-6.4 -15.4l.7 .7m12.1 -.7l-.7 .7m0 11.4l.7 .7m-12.1 -.7l-.7 .7"></path> </svg> </button> <button id="header__moon" onclick="toLightMode()" title="Switch to light mode" class="relative w-10 h-10 focus:outline-none focus:shadow-outline text-gray-500"> <svg style="width:24px;height:24px" viewBox="0 0 24 24"> <path fill="currentColor" d="M17.75,4.09L15.22,6.03L16.13,9.09L13.5,7.28L10.87,9.09L11.78,6.03L9.25,4.09L12.44,4L13.5,1L14.56,4L17.75,4.09M21.25,11L19.61,12.25L20.2,14.23L18.5,13.06L16.8,14.23L17.39,12.25L15.75,11L17.81,10.95L18.5,9L19.19,10.95L21.25,11M18.97,15.95C19.8,15.87 20.69,17.05 20.16,17.8C19.84,18.25 19.5,18.67 19.08,19.07C15.17,23 8.84,23 4.94,19.07C1.03,15.17 1.03,8.83 4.94,4.93C5.34,4.53 5.76,4.17 6.21,3.85C6.96,3.32 8.14,4.21 8.06,5.04C7.79,7.9 8.75,10.87 10.95,13.06C13.14,15.26 16.1,16.22 18.97,15.95M17.33,17.97C14.5,17.81 11.7,16.64 9.53,14.5C7.36,12.31 6.2,9.5 6.04,6.68C3.23,9.82 3.34,14.64 6.35,17.66C9.37,20.67 14.19,20.78 17.33,17.97Z" /> </svg> </button> <button id="header__indeterminate" onclick="toDarkMode()" title="Switch to dark mode" class="relative w-10 h-10 focus:outline-none focus:shadow-outline text-gray-500"> <svg style="width:24px;height:24px" viewBox="0 0 24 24"> <path fill="currentColor" d="M12 2A10 10 0 0 0 2 12A10 10 0 0 0 12 22A10 10 0 0 0 22 12A10 10 0 0 0 12 2M12 4A8 8 0 0 1 20 12A8 8 0 0 1 12 20V4Z" /> </svg> </button> <button class="ml-2 relative w-10 h-10 p-2 text-red-600 lg:hidden focus:outline-none focus:shadow-outline" aria-label="Menu" @click.prevent="navIsOpen = !navIsOpen"> <svg x-show="! navIsOpen" x-transition.opacity class="absolute inset-0 mt-2 ml-2 w-6 h-6" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg> <svg x-show="navIsOpen" x-transition.opacity x-cloak class="absolute inset-0 mt-2 ml-2 w-6 h-6" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg> </button> </div> </div> <span :class="{ 'shadow-sm': navIsOpen }" class="absolute inset-0 z-20 pointer-events-none"></span> </div> <div x-show="navIsOpen" x-transition:enter="duration-150" x-transition:leave="duration-100 ease-in" x-cloak > <nav x-show="navIsOpen" x-cloak class="absolute w-full transform origin-top shadow-sm z-10" x-transition:enter="duration-150 ease-out" x-transition:enter-start="opacity-0 -translate-y-8 scale-75" x-transition:enter-end="opacity-100 scale-100" x-transition:leave="duration-100 ease-in" x-transition:leave-start="opacity-100 scale-100" x-transition:leave-end="opacity-0 -translate-y-8 scale-75" > <div class="relative p-8 bg-white docs_sidebar dark:bg-dark-600"> <ul> <li> <h2>Prologue</h2> <ul> <li> <a href="/docs/11.x/releases">Release Notes</a> </li> <li> <a href="/docs/11.x/upgrade">Upgrade Guide</a> </li> <li> <a href="/docs/11.x/contributions">Contribution Guide</a> </li> </ul> </li> <li> <h2>Getting Started</h2> <ul> <li> <a href="/docs/11.x/installation">Installation</a> </li> <li> <a href="/docs/11.x/configuration">Configuration</a> </li> <li> <a href="/docs/11.x/structure">Directory Structure</a> </li> <li> <a href="/docs/11.x/frontend">Frontend</a> </li> <li> <a href="/docs/11.x/starter-kits">Starter Kits</a> </li> <li> <a href="/docs/11.x/deployment">Deployment</a> </li> </ul> </li> <li> <h2>Architecture Concepts</h2> <ul> <li> <a href="/docs/11.x/lifecycle">Request Lifecycle</a> </li> <li> <a href="/docs/11.x/container">Service Container</a> </li> <li> <a href="/docs/11.x/providers">Service Providers</a> </li> <li> <a href="/docs/11.x/facades">Facades</a> </li> </ul> </li> <li class="sub--on"> <h2>The Basics</h2> <ul> <li> <a href="/docs/11.x/routing">Routing</a> </li> <li> <a href="/docs/11.x/middleware">Middleware</a> </li> <li> <a href="/docs/11.x/csrf">CSRF Protection</a> </li> <li> <a href="/docs/11.x/controllers">Controllers</a> </li> <li> <a href="/docs/11.x/requests">Requests</a> </li> <li> <a href="/docs/11.x/responses">Responses</a> </li> <li> <a href="/docs/11.x/views">Views</a> </li> <li class="active"> <a href="/docs/11.x/blade">Blade Templates</a> </li> <li> <a href="/docs/11.x/vite">Asset Bundling</a> </li> <li> <a href="/docs/11.x/urls">URL Generation</a> </li> <li> <a href="/docs/11.x/session">Session</a> </li> <li> <a href="/docs/11.x/validation">Validation</a> </li> <li> <a href="/docs/11.x/errors">Error Handling</a> </li> <li> <a href="/docs/11.x/logging">Logging</a> </li> </ul> </li> <li> <h2>Digging Deeper</h2> <ul> <li> <a href="/docs/11.x/artisan">Artisan Console</a> </li> <li> <a href="/docs/11.x/broadcasting">Broadcasting</a> </li> <li> <a href="/docs/11.x/cache">Cache</a> </li> <li> <a href="/docs/11.x/collections">Collections</a> </li> <li> <a href="/docs/11.x/concurrency">Concurrency</a> </li> <li> <a href="/docs/11.x/context">Context</a> </li> <li> <a href="/docs/11.x/contracts">Contracts</a> </li> <li> <a href="/docs/11.x/events">Events</a> </li> <li> <a href="/docs/11.x/filesystem">File Storage</a> </li> <li> <a href="/docs/11.x/helpers">Helpers</a> </li> <li> <a href="/docs/11.x/http-client">HTTP Client</a> </li> <li> <a href="/docs/11.x/localization">Localization</a> </li> <li> <a href="/docs/11.x/mail">Mail</a> </li> <li> <a href="/docs/11.x/notifications">Notifications</a> </li> <li> <a href="/docs/11.x/packages">Package Development</a> </li> <li> <a href="/docs/11.x/processes">Processes</a> </li> <li> <a href="/docs/11.x/queues">Queues</a> </li> <li> <a href="/docs/11.x/rate-limiting">Rate Limiting</a> </li> <li> <a href="/docs/11.x/strings">Strings</a> </li> <li> <a href="/docs/11.x/scheduling">Task Scheduling</a> </li> </ul> </li> <li> <h2>Security</h2> <ul> <li> <a href="/docs/11.x/authentication">Authentication</a> </li> <li> <a href="/docs/11.x/authorization">Authorization</a> </li> <li> <a href="/docs/11.x/verification">Email Verification</a> </li> <li> <a href="/docs/11.x/encryption">Encryption</a> </li> <li> <a href="/docs/11.x/hashing">Hashing</a> </li> <li> <a href="/docs/11.x/passwords">Password Reset</a> </li> </ul> </li> <li> <h2>Database</h2> <ul> <li> <a href="/docs/11.x/database">Getting Started</a> </li> <li> <a href="/docs/11.x/queries">Query Builder</a> </li> <li> <a href="/docs/11.x/pagination">Pagination</a> </li> <li> <a href="/docs/11.x/migrations">Migrations</a> </li> <li> <a href="/docs/11.x/seeding">Seeding</a> </li> <li> <a href="/docs/11.x/redis">Redis</a> </li> <li> <a href="/docs/11.x/mongodb">MongoDB</a> </li> </ul> </li> <li> <h2>Eloquent ORM</h2> <ul> <li> <a href="/docs/11.x/eloquent">Getting Started</a> </li> <li> <a href="/docs/11.x/eloquent-relationships">Relationships</a> </li> <li> <a href="/docs/11.x/eloquent-collections">Collections</a> </li> <li> <a href="/docs/11.x/eloquent-mutators">Mutators / Casts</a> </li> <li> <a href="/docs/11.x/eloquent-resources">API Resources</a> </li> <li> <a href="/docs/11.x/eloquent-serialization">Serialization</a> </li> <li> <a href="/docs/11.x/eloquent-factories">Factories</a> </li> </ul> </li> <li> <h2>Testing</h2> <ul> <li> <a href="/docs/11.x/testing">Getting Started</a> </li> <li> <a href="/docs/11.x/http-tests">HTTP Tests</a> </li> <li> <a href="/docs/11.x/console-tests">Console Tests</a> </li> <li> <a href="/docs/11.x/dusk">Browser Tests</a> </li> <li> <a href="/docs/11.x/database-testing">Database</a> </li> <li> <a href="/docs/11.x/mocking">Mocking</a> </li> </ul> </li> <li> <h2>Packages</h2> <ul> <li> <a href="/docs/11.x/starter-kits#laravel-breeze">Breeze</a> </li> <li> <a href="/docs/11.x/billing">Cashier (Stripe)</a> </li> <li> <a href="/docs/11.x/cashier-paddle">Cashier (Paddle)</a> </li> <li> <a href="/docs/11.x/dusk">Dusk</a> </li> <li> <a href="/docs/11.x/envoy">Envoy</a> </li> <li> <a href="/docs/11.x/fortify">Fortify</a> </li> <li> <a href="/docs/11.x/folio">Folio</a> </li> <li> <a href="/docs/11.x/homestead">Homestead</a> </li> <li> <a href="/docs/11.x/horizon">Horizon</a> </li> <li> <a href="https://jetstream.laravel.com">Jetstream</a> </li> <li> <a href="/docs/11.x/mix">Mix</a> </li> <li> <a href="/docs/11.x/octane">Octane</a> </li> <li> <a href="/docs/11.x/passport">Passport</a> </li> <li> <a href="/docs/11.x/pennant">Pennant</a> </li> <li> <a href="/docs/11.x/pint">Pint</a> </li> <li> <a href="/docs/11.x/precognition">Precognition</a> </li> <li> <a href="/docs/11.x/prompts">Prompts</a> </li> <li> <a href="/docs/11.x/pulse">Pulse</a> </li> <li> <a href="/docs/11.x/reverb">Reverb</a> </li> <li> <a href="/docs/11.x/sail">Sail</a> </li> <li> <a href="/docs/11.x/sanctum">Sanctum</a> </li> <li> <a href="/docs/11.x/scout">Scout</a> </li> <li> <a href="/docs/11.x/socialite">Socialite</a> </li> <li> <a href="/docs/11.x/telescope">Telescope</a> </li> <li> <a href="/docs/11.x/valet">Valet</a> </li> </ul> </li> <li> <a href="/api/11.x">API Documentation</a> </li> </ul> </div> </nav> </div> </header> <section class="flex-1 dark:bg-dark-700"> <div class="max-w-screen-lg px-8 sm:px-16 lg:px-24"> <div class="flex flex-col items-end border-b border-gray-200 py-1 transition-colors dark:border-gray-700 lg:mt-8 lg:flex-row-reverse"> <div class="hidden lg:flex items-center justify-center ml-8"> <button id="header__sun" onclick="toSystemMode()" title="Switch to system theme" class="relative w-10 h-10 focus:outline-none focus:shadow-outline text-gray-500"> <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-sun" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <circle cx="12" cy="12" r="4"></circle> <path d="M3 12h1m8 -9v1m8 8h1m-9 8v1m-6.4 -15.4l.7 .7m12.1 -.7l-.7 .7m0 11.4l.7 .7m-12.1 -.7l-.7 .7"></path> </svg> </button> <button id="header__moon" onclick="toLightMode()" title="Switch to light mode" class="relative w-10 h-10 focus:outline-none focus:shadow-outline text-gray-500"> <svg style="width:24px;height:24px" viewBox="0 0 24 24"> <path fill="currentColor" d="M17.75,4.09L15.22,6.03L16.13,9.09L13.5,7.28L10.87,9.09L11.78,6.03L9.25,4.09L12.44,4L13.5,1L14.56,4L17.75,4.09M21.25,11L19.61,12.25L20.2,14.23L18.5,13.06L16.8,14.23L17.39,12.25L15.75,11L17.81,10.95L18.5,9L19.19,10.95L21.25,11M18.97,15.95C19.8,15.87 20.69,17.05 20.16,17.8C19.84,18.25 19.5,18.67 19.08,19.07C15.17,23 8.84,23 4.94,19.07C1.03,15.17 1.03,8.83 4.94,4.93C5.34,4.53 5.76,4.17 6.21,3.85C6.96,3.32 8.14,4.21 8.06,5.04C7.79,7.9 8.75,10.87 10.95,13.06C13.14,15.26 16.1,16.22 18.97,15.95M17.33,17.97C14.5,17.81 11.7,16.64 9.53,14.5C7.36,12.31 6.2,9.5 6.04,6.68C3.23,9.82 3.34,14.64 6.35,17.66C9.37,20.67 14.19,20.78 17.33,17.97Z" /> </svg> </button> <button id="header__indeterminate" onclick="toDarkMode()" title="Switch to dark mode" class="relative w-10 h-10 focus:outline-none focus:shadow-outline text-gray-500"> <svg style="width:24px;height:24px" viewBox="0 0 24 24"> <path fill="currentColor" d="M12 2A10 10 0 0 0 2 12A10 10 0 0 0 12 22A10 10 0 0 0 22 12A10 10 0 0 0 12 2M12 4A8 8 0 0 1 20 12A8 8 0 0 1 12 20V4Z" /> </svg> </button> </div> <div class="w-full lg:w-40 lg:pl-12"> <div> <label class="text-gray-600 text-xs tracking-widest uppercase dark:text-gray-500" for="version-switcher">Version</label> <div x-data class="relative w-full bg-white transition-all duration-500 focus-within:border-gray-600 dark:bg-gray-800"> <select id="version-switcher" aria-label="Laravel version" class="appearance-none flex-1 w-full px-0 py-1 placeholder-gray-900 tracking-wide bg-white border-transparent focus:outline-none dark:bg-dark-700 dark:text-gray-400 dark:placeholder-gray-500" @change="window.location = $event.target.value" > <option value="https://laravel.com/docs/master/blade">Master</option> <option selected value="https://laravel.com/docs/11.x/blade">11.x</option> <option value="https://laravel.com/docs/10.x/blade">10.x</option> <option value="https://laravel.com/docs/9.x/blade">9.x</option> <option value="https://laravel.com/docs/8.x/blade">8.x</option> <option value="https://laravel.com/docs/7.x/blade">7.x</option> <option value="https://laravel.com/docs/6.x/blade">6.x</option> <option value="https://laravel.com/docs/5.8/blade">5.8</option> <option value="https://laravel.com/docs/5.7/blade">5.7</option> <option value="https://laravel.com/docs/5.6/blade">5.6</option> <option value="https://laravel.com/docs/5.5/blade">5.5</option> <option value="https://laravel.com/docs/5.4/blade">5.4</option> <option value="https://laravel.com/docs/5.3/blade">5.3</option> <option value="https://laravel.com/docs/5.2/blade">5.2</option> <option value="https://laravel.com/docs/5.1/blade">5.1</option> <option value="https://laravel.com/docs/5.0/blade">5.0</option> <option value="https://laravel.com/docs/4.2/blade">4.2</option> </select> <img class="absolute inset-y-0 right-0 mt-2.5 w-2.5 h-2.5 text-gray-900 pointer-events-none dark:hidden" src="/img/icons/drop_arrow.min.svg" alt="" width="10" height="10"> <img class="absolute inset-y-0 right-0 mt-2.5 w-2.5 h-2.5 text-gray-900 pointer-events-none hidden dark:block" src="/img/icons/drop_arrow.dark.min.svg" alt="" width="10" height="10"> </div> </div> </div> <div class="relative mt-8 flex items-center justify-end w-full h-10 lg:mt-0"> <div class="flex-1 flex items-center"> <button id="docsearch" class="text-gray-800 transition-colors dark:text-gray-400 w-full"></button> </div> </div> </div> <section class="mt-8 md:mt-16"> <section class="docs_main max-w-prose"> <div id="main-content"> <h1>Blade Templates</h1> <ul> <li> <a href="#introduction">Introduction</a> <ul> <li> <a href="#supercharging-blade-with-livewire">Supercharging Blade With Livewire</a> </li> </ul> </li> <li> <a href="#displaying-data">Displaying Data</a> <ul> <li> <a href="#html-entity-encoding">HTML Entity Encoding</a> </li> <li> <a href="#blade-and-javascript-frameworks">Blade and JavaScript Frameworks</a> </li> </ul> </li> <li> <a href="#blade-directives">Blade Directives</a> <ul> <li> <a href="#if-statements">If Statements</a> </li> <li> <a href="#switch-statements">Switch Statements</a> </li> <li> <a href="#loops">Loops</a> </li> <li> <a href="#the-loop-variable">The Loop Variable</a> </li> <li> <a href="#conditional-classes">Conditional Classes</a> </li> <li> <a href="#additional-attributes">Additional Attributes</a> </li> <li> <a href="#including-subviews">Including Subviews</a> </li> <li> <a href="#the-once-directive">The <code>@once</code> Directive</a> </li> <li> <a href="#raw-php">Raw PHP</a> </li> <li> <a href="#comments">Comments</a> </li> </ul> </li> <li> <a href="#components">Components</a> <ul> <li> <a href="#rendering-components">Rendering Components</a> </li> <li> <a href="#index-components">Index Components</a> </li> <li> <a href="#passing-data-to-components">Passing Data to Components</a> </li> <li> <a href="#component-attributes">Component Attributes</a> </li> <li> <a href="#reserved-keywords">Reserved Keywords</a> </li> <li> <a href="#slots">Slots</a> </li> <li> <a href="#inline-component-views">Inline Component Views</a> </li> <li> <a href="#dynamic-components">Dynamic Components</a> </li> <li> <a href="#manually-registering-components">Manually Registering Components</a> </li> </ul> </li> <li> <a href="#anonymous-components">Anonymous Components</a> <ul> <li> <a href="#anonymous-index-components">Anonymous Index Components</a> </li> <li> <a href="#data-properties-attributes">Data Properties / Attributes</a> </li> <li> <a href="#accessing-parent-data">Accessing Parent Data</a> </li> <li> <a href="#anonymous-component-paths">Anonymous Components Paths</a> </li> </ul> </li> <li> <a href="#building-layouts">Building Layouts</a> <ul> <li> <a href="#layouts-using-components">Layouts Using Components</a> </li> <li> <a href="#layouts-using-template-inheritance">Layouts Using Template Inheritance</a> </li> </ul> </li> <li> <a href="#forms">Forms</a> <ul> <li> <a href="#csrf-field">CSRF Field</a> </li> <li> <a href="#method-field">Method Field</a> </li> <li> <a href="#validation-errors">Validation Errors</a> </li> </ul> </li> <li> <a href="#stacks">Stacks</a> </li> <li> <a href="#service-injection">Service Injection</a> </li> <li> <a href="#rendering-inline-blade-templates">Rendering Inline Blade Templates</a> </li> <li> <a href="#rendering-blade-fragments">Rendering Blade Fragments</a> </li> <li> <a href="#extending-blade">Extending Blade</a> <ul> <li> <a href="#custom-echo-handlers">Custom Echo Handlers</a> </li> <li> <a href="#custom-if-statements">Custom If Statements</a> </li> </ul> </li> </ul> <h2 id="introduction"><a href="#introduction">Introduction</a></h2> <p>Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates. In fact, all Blade templates are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application. Blade template files use the <code>.blade.php</code> file extension and are typically stored in the <code>resources/views</code> directory.</p> <p>Blade views may be returned from routes or controllers using the global <code>view</code> helper. Of course, as mentioned in the documentation on <a href="/docs/11.x/views">views</a>, data may be passed to the Blade view using the <code>view</code> helper's second argument:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #FFCB8B;">Route</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">get</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">/</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">()</span><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">view</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">greeting</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">[</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #82AAFF;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #82AAFF;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Finn</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">]);</span></div><div class='line'><span style="color: #BFC7D5;">});</span></div></code></pre> <h3 id="supercharging-blade-with-livewire"><a href="#supercharging-blade-with-livewire">Supercharging Blade With Livewire</a></h3> <p>Want to take your Blade templates to the next level and build dynamic interfaces with ease? Check out <a href="https://livewire.laravel.com">Laravel Livewire</a>. Livewire allows you to write Blade components that are augmented with dynamic functionality that would typically only be possible via frontend frameworks like React or Vue, providing a great approach to building modern, reactive frontends without the complexities, client-side rendering, or build steps of many JavaScript frameworks.</p> <h2 id="displaying-data"><a href="#displaying-data">Displaying Data</a></h2> <p>You may display data that is passed to your Blade views by wrapping the variable in curly braces. For example, given the following route:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #FFCB8B;">Route</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">get</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">/</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">()</span><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">view</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">welcome</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">[</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #82AAFF;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #82AAFF;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Samantha</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">]);</span></div><div class='line'><span style="color: #BFC7D5;">});</span></div></code></pre> <p>You may display the contents of the <code>name</code> variable like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">Hello, </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$name</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span><span style="color: #BFC7D5;">.</span></div></code></pre> </div> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-purple-600"> <div class="opacity-75"><svg width="28" height="40" viewBox="0 0 28 40" xmlns="http://www.w3.org/2000/svg"><title>lightbulb</title><path d="M12 28h4v-8h-4v8zM8 40h12v-8H8v8zm13.98-14.52c-1.001.705-1.661 1.545-1.98 2.52H8c-.416-.959-1.076-1.799-1.98-2.52A13.99 13.99 0 0 1 0 14C0 6.272 6.272 0 14 0s14 6.272 14 14a13.99 13.99 0 0 1-6.02 11.48z" fill="#FFF" fill-rule="nonzero"/></svg></div> </div> <p class="mb-0 lg:ml-6 callout"> Blade's <code>{{ }}</code> echo statements are automatically sent through PHP's <code>htmlspecialchars</code> function to prevent XSS attacks.</p> </div> <p>You are not limited to displaying the contents of the variables passed to the view. You may also echo the results of any PHP function. In fact, you can put any PHP code you wish inside of a Blade echo statement:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">The current UNIX timestamp is </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">time</span><span style="color: #BFC7D5;">() </span><span style="color: #89DDFF;">}}</span><span style="color: #BFC7D5;">.</span></div></code></pre> </div> <h3 id="html-entity-encoding"><a href="#html-entity-encoding">HTML Entity Encoding</a></h3> <p>By default, Blade (and the Laravel <code>e</code> function) will double encode HTML entities. If you would like to disable double encoding, call the <code>Blade::withoutDoubleEncoding</code> method from the <code>boot</code> method of your <code>AppServiceProvider</code>:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #D3423E;">&lt;?php</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">namespace</span><span style="color: #BFC7D5;"> App\Providers;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\Facades\</span><span style="color: #FFCB8B;">Blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\</span><span style="color: #FFCB8B;">ServiceProvider</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">class</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB6B;">AppServiceProvider</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">extends</span><span style="color: #BFC7D5;"> </span><span style="color: #A9C77D;">ServiceProvider</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Bootstrap any application services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">boot</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">withoutDoubleEncoding</span><span style="color: #BFC7D5;">();</span></div><div class='line'><span style="color: #BFC7D5;"> }</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <h4 id="displaying-unescaped-data"><a href="#displaying-unescaped-data">Displaying Unescaped Data</a></h4> <p>By default, Blade <code>{{ }}</code> statements are automatically sent through PHP's <code>htmlspecialchars</code> function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">Hello, </span><span style="color: #89DDFF;">{!!</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$name</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">!!}</span><span style="color: #BFC7D5;">.</span></div></code></pre> </div> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-red-600"> <div class="opacity-75"><svg width="6" height="35" viewBox="0 0 6 35" xmlns="http://www.w3.org/2000/svg"><title>exclamation</title><path d="M0 29h6v6H0v-6zM0 0h6v24H0V0z" fill="#FFF" fill-rule="nonzero"/></svg> </div> </div> <p class="mb-0 lg:ml-6 callout"> Be very careful when echoing content that is supplied by users of your application. You should typically use the escaped, double curly brace syntax to prevent XSS attacks when displaying user supplied data.</p> </div> <h3 id="blade-and-javascript-frameworks"><a href="#blade-and-javascript-frameworks">Blade and JavaScript Frameworks</a></h3> <p>Since many JavaScript frameworks also use &quot;curly&quot; braces to indicate a given expression should be displayed in the browser, you may use the <code>@</code> symbol to inform the Blade rendering engine an expression should remain untouched. For example:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">h1</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">Laravel</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">h1</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;">Hello, </span><span style="color: #FFCB6B;">@</span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">name</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span><span style="color: #BFC7D5;">.</span></div></code></pre> </div> <p>In this example, the <code>@</code> symbol will be removed by Blade; however, <code>{{ name }}</code> expression will remain untouched by the Blade engine, allowing it to be rendered by your JavaScript framework.</p> <p>The <code>@</code> symbol may also be used to escape Blade directives:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">{{--</span><span style="color: #697098;"> Blade template </span><span style="color: #697098;">--}}</span></div><div class='line'><span style="color: #BFC7D5;">@@if()</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> HTML output </span><span style="color: #697098;">--&gt;</span></div><div class='line'><span style="color: #C792EA;">@if</span><span style="color: #BFC7D5;">()</span></div></code></pre> </div> <h4 id="rendering-json"><a href="#rendering-json">Rendering JSON</a></h4> <p>Sometimes you may pass an array to your view with the intention of rendering it as JSON in order to initialize a JavaScript variable. For example:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">var</span><span style="color: #BFC7D5;"> app </span><span style="color: #C792EA;">=</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">&lt;</span><span style="color: #89DDFF;">?</span><span style="color: #BFC7D5;">php echo </span><span style="color: #82AAFF;">json_encode</span><span style="color: #BFC7D5;">($array); </span><span style="color: #89DDFF;">?</span><span style="color: #C792EA;">&gt;</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #C792EA;">&lt;</span><span style="color: #89DDFF;">/</span><span style="color: #BFC7D5;">script</span><span style="color: #C792EA;">&gt;</span></div></code></pre> </div> <p>However, instead of manually calling <code>json_encode</code>, you may use the <code>Illuminate\Support\Js::from</code> method directive. The <code>from</code> method accepts the same arguments as PHP's <code>json_encode</code> function; however, it will ensure that the resulting JSON is properly escaped for inclusion within HTML quotes. The <code>from</code> method will return a string <code>JSON.parse</code> JavaScript statement that will convert the given object or array into a valid JavaScript object:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">var</span><span style="color: #BFC7D5;"> app </span><span style="color: #C792EA;">=</span><span style="color: #BFC7D5;"> {{ Illuminate\Support\Js::</span><span style="color: #82AAFF;">from</span><span style="color: #BFC7D5;">($array) }};</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>The latest versions of the Laravel application skeleton include a <code>Js</code> facade, which provides convenient access to this functionality within your Blade templates:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">var</span><span style="color: #BFC7D5;"> app </span><span style="color: #C792EA;">=</span><span style="color: #BFC7D5;"> {{ Js::</span><span style="color: #82AAFF;">from</span><span style="color: #BFC7D5;">($array) }};</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-red-600"> <div class="opacity-75"><svg width="6" height="35" viewBox="0 0 6 35" xmlns="http://www.w3.org/2000/svg"><title>exclamation</title><path d="M0 29h6v6H0v-6zM0 0h6v24H0V0z" fill="#FFF" fill-rule="nonzero"/></svg> </div> </div> <p class="mb-0 lg:ml-6 callout"> You should only use the <code>Js::from</code> method to render existing variables as JSON. The Blade templating is based on regular expressions and attempts to pass a complex expression to the directive may cause unexpected failures.</p> </div> <h4 id="the-at-verbatim-directive"><a href="#the-at-verbatim-directive">The <code>@verbatim</code> Directive</a></h4> <p>If you are displaying JavaScript variables in a large portion of your template, you may wrap the HTML in the <code>@verbatim</code> directive so that you do not have to prefix each Blade echo statement with an <code>@</code> symbol:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@verbatim</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">container</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Hello, </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">name</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span><span style="color: #BFC7D5;">.</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endverbatim</span></div></code></pre> </div> <h2 id="blade-directives"><a href="#blade-directives">Blade Directives</a></h2> <p>In addition to template inheritance and displaying data, Blade also provides convenient shortcuts for common PHP control structures, such as conditional statements and loops. These shortcuts provide a very clean, terse way of working with PHP control structures while also remaining familiar to their PHP counterparts.</p> <h3 id="if-statements"><a href="#if-statements">If Statements</a></h3> <p>You may construct <code>if</code> statements using the <code>@if</code>, <code>@elseif</code>, <code>@else</code>, and <code>@endif</code> directives. These directives function identically to their PHP counterparts:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #89DDFF;">count</span><span style="color: #BFC7D5;">($</span><span style="color: #BEC5D4;">records</span><span style="color: #BFC7D5;">) </span><span style="color: #C792EA;">===</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">1</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> I have one record!</span></div><div class='line'><span style="color: #C792EA;">@elseif </span><span style="color: #BFC7D5;">(</span><span style="color: #89DDFF;">count</span><span style="color: #BFC7D5;">($</span><span style="color: #BEC5D4;">records</span><span style="color: #BFC7D5;">) </span><span style="color: #C792EA;">&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">1</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> I have multiple records!</span></div><div class='line'><span style="color: #C792EA;">@else</span></div><div class='line'><span style="color: #BFC7D5;"> I don&#39;t have any records!</span></div><div class='line'><span style="color: #C792EA;">@endif</span></div></code></pre> </div> <p>For convenience, Blade also provides an <code>@unless</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@unless </span><span style="color: #BFC7D5;">(</span><span style="color: #FFCB6B;">Auth</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">check</span><span style="color: #BFC7D5;">())</span></div><div class='line'><span style="color: #BFC7D5;"> You are not signed in.</span></div><div class='line'><span style="color: #C792EA;">@endunless</span></div></code></pre> </div> <p>In addition to the conditional directives already discussed, the <code>@isset</code> and <code>@empty</code> directives may be used as convenient shortcuts for their respective PHP functions:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@isset</span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$records</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> // $records is defined and is not null...</span></div><div class='line'><span style="color: #C792EA;">@endisset</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@empty</span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$records</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> // $records is &quot;empty&quot;...</span></div><div class='line'><span style="color: #C792EA;">@endempty</span></div></code></pre> </div> <h4 id="authentication-directives"><a href="#authentication-directives">Authentication Directives</a></h4> <p>The <code>@auth</code> and <code>@guest</code> directives may be used to quickly determine if the current user is <a href="/docs/11.x/authentication">authenticated</a> or is a guest:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@auth</span></div><div class='line'><span style="color: #BFC7D5;"> // The user is authenticated...</span></div><div class='line'><span style="color: #C792EA;">@endauth</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@guest</span></div><div class='line'><span style="color: #BFC7D5;"> // The user is not authenticated...</span></div><div class='line'><span style="color: #C792EA;">@endguest</span></div></code></pre> </div> <p>If needed, you may specify the authentication guard that should be checked when using the <code>@auth</code> and <code>@guest</code> directives:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@auth</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">admin</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> // The user is authenticated...</span></div><div class='line'><span style="color: #C792EA;">@endauth</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@guest</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">admin</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> // The user is not authenticated...</span></div><div class='line'><span style="color: #C792EA;">@endguest</span></div></code></pre> </div> <h4 id="environment-directives"><a href="#environment-directives">Environment Directives</a></h4> <p>You may check if the application is running in the production environment using the <code>@production</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@production</span></div><div class='line'><span style="color: #BFC7D5;"> // Production specific content...</span></div><div class='line'><span style="color: #C792EA;">@endproduction</span></div></code></pre> </div> <p>Or, you may determine if the application is running in a specific environment using the <code>@env</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #82AAFF;">@env</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">staging</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> // The application is running in &quot;staging&quot;...</span></div><div class='line'><span style="color: #82AAFF;">@endenv</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #82AAFF;">@env</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">staging</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">production</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span></div><div class='line'><span style="color: #BFC7D5;"> // The application is running in &quot;staging&quot; or &quot;production&quot;...</span></div><div class='line'><span style="color: #82AAFF;">@endenv</span></div></code></pre> </div> <h4 id="section-directives"><a href="#section-directives">Section Directives</a></h4> <p>You may determine if a template inheritance section has content using the <code>@hasSection</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@hasSection</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">navigation</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">pull-right</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@yield</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">navigation</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">clearfix</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endif</span></div></code></pre> </div> <p>You may use the <code>sectionMissing</code> directive to determine if a section does not have content:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@sectionMissing</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">navigation</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">pull-right</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@include</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">default-navigation</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endif</span></div></code></pre> </div> <h4 id="session-directives"><a href="#session-directives">Session Directives</a></h4> <p>The <code>@session</code> directive may be used to determine if a <a href="/docs/11.x/session">session</a> value exists. If the session value exists, the template contents within the <code>@session</code> and <code>@endsession</code> directives will be evaluated. Within the <code>@session</code> directive's contents, you may echo the <code>$value</code> variable to display the session value:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #82AAFF;">@session</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">status</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">p-4 bg-green-100</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$value</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #82AAFF;">@endsession</span></div></code></pre> </div> <h3 id="switch-statements"><a href="#switch-statements">Switch Statements</a></h3> <p>Switch statements can be constructed using the <code>@switch</code>, <code>@case</code>, <code>@break</code>, <code>@default</code> and <code>@endswitch</code> directives:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@switch</span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$i</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@case</span><span style="color: #BFC7D5;">(</span><span style="color: #F78C6C;">1</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> First case...</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@break</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@case</span><span style="color: #BFC7D5;">(</span><span style="color: #F78C6C;">2</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> Second case...</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@break</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@default</span></div><div class='line'><span style="color: #BFC7D5;"> Default case...</span></div><div class='line'><span style="color: #C792EA;">@endswitch</span></div></code></pre> </div> <h3 id="loops"><a href="#loops">Loops</a></h3> <p>In addition to conditional statements, Blade provides simple directives for working with PHP's loop structures. Again, each of these directives functions identically to their PHP counterparts:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@for </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$i</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">=</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">0</span><span style="color: #BFC7D5;">; </span><span style="color: #BEC5D4;">$i</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">&lt;</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">10</span><span style="color: #BFC7D5;">; </span><span style="color: #BEC5D4;">$i</span><span style="color: #89DDFF;">++</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> The current value is </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$i</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #C792EA;">@endfor</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$users</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">This is user </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;id</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endforeach</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@forelse </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$users</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;name</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@empty</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">No users</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endforelse</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@while </span><span style="color: #BFC7D5;">(</span><span style="color: #82AAFF;">true</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">I&#39;m looping forever.</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endwhile</span></div></code></pre> </div> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-purple-600"> <div class="opacity-75"><svg width="28" height="40" viewBox="0 0 28 40" xmlns="http://www.w3.org/2000/svg"><title>lightbulb</title><path d="M12 28h4v-8h-4v8zM8 40h12v-8H8v8zm13.98-14.52c-1.001.705-1.661 1.545-1.98 2.52H8c-.416-.959-1.076-1.799-1.98-2.52A13.99 13.99 0 0 1 0 14C0 6.272 6.272 0 14 0s14 6.272 14 14a13.99 13.99 0 0 1-6.02 11.48z" fill="#FFF" fill-rule="nonzero"/></svg></div> </div> <p class="mb-0 lg:ml-6 callout"> While iterating through a <code>foreach</code> loop, you may use the <a href="#the-loop-variable">loop variable</a> to gain valuable information about the loop, such as whether you are in the first or last iteration through the loop.</p> </div> <p>When using loops you may also skip the current iteration or end the loop using the <code>@continue</code> and <code>@break</code> directives:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$users</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;type</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">==</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">1</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@continue</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endif</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;name</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;number</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">==</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">5</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@break</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endif</span></div><div class='line'><span style="color: #C792EA;">@endforeach</span></div></code></pre> </div> <p>You may also include the continuation or break condition within the directive declaration:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$users</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@continue</span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;type</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">==</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">1</span><span style="color: #BFC7D5;">)</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;name</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@break</span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;number</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">==</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">5</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #C792EA;">@endforeach</span></div></code></pre> </div> <h3 id="the-loop-variable"><a href="#the-loop-variable">The Loop Variable</a></h3> <p>While iterating through a <code>foreach</code> loop, a <code>$loop</code> variable will be available inside of your loop. This variable provides access to some useful bits of information such as the current loop index and whether this is the first or last iteration through the loop:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$users</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$loop</span><span style="color: #89DDFF;">-&gt;first</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> This is the first iteration.</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endif</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$loop</span><span style="color: #89DDFF;">-&gt;last</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> This is the last iteration.</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endif</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">This is user </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;id</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endforeach</span></div></code></pre> </div> <p>If you are in a nested loop, you may access the parent loop's <code>$loop</code> variable via the <code>parent</code> property:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$users</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;posts</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$post</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$loop</span><span style="color: #89DDFF;">-&gt;parent-&gt;first</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> This is the first iteration of the parent loop.</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endif</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endforeach</span></div><div class='line'><span style="color: #C792EA;">@endforeach</span></div></code></pre> </div> <p>The <code>$loop</code> variable also contains a variety of other useful properties:</p> <div class="overflow-auto"> <table> <thead> <tr> <th>Property</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>$loop-&gt;index</code></td> <td>The index of the current loop iteration (starts at 0).</td> </tr> <tr> <td><code>$loop-&gt;iteration</code></td> <td>The current loop iteration (starts at 1).</td> </tr> <tr> <td><code>$loop-&gt;remaining</code></td> <td>The iterations remaining in the loop.</td> </tr> <tr> <td><code>$loop-&gt;count</code></td> <td>The total number of items in the array being iterated.</td> </tr> <tr> <td><code>$loop-&gt;first</code></td> <td>Whether this is the first iteration through the loop.</td> </tr> <tr> <td><code>$loop-&gt;last</code></td> <td>Whether this is the last iteration through the loop.</td> </tr> <tr> <td><code>$loop-&gt;even</code></td> <td>Whether this is an even iteration through the loop.</td> </tr> <tr> <td><code>$loop-&gt;odd</code></td> <td>Whether this is an odd iteration through the loop.</td> </tr> <tr> <td><code>$loop-&gt;depth</code></td> <td>The nesting level of the current loop.</td> </tr> <tr> <td><code>$loop-&gt;parent</code></td> <td>When in a nested loop, the parent's loop variable.</td> </tr> </tbody> </table> </div> <h3 id="conditional-classes"><a href="#conditional-classes">Conditional Classes &amp; Styles</a></h3> <p>The <code>@class</code> directive conditionally compiles a CSS class string. The directive accepts an array of classes where the array key contains the class or classes you wish to add, while the value is a boolean expression. If the array element has a numeric key, it will always be included in the rendered class list:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #D3423E;">@php</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$isActive</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">=</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">false</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$hasError</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">=</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">true</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #D3423E;">@endphp</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;"> </span><span style="color: #82AAFF;">@class</span><span style="color: #89DDFF;">(</span><span style="color: #BFC7D5;">[</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">p-4</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;">,</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">font-bold</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #BEC5D4;">$isActive</span><span style="color: #89DDFF;">,</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">text-gray-500</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #C792EA;">!</span><span style="color: #89DDFF;"> </span><span style="color: #BEC5D4;">$isActive</span><span style="color: #89DDFF;">,</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">bg-red</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #BEC5D4;">$hasError</span><span style="color: #89DDFF;">,</span></div><div class='line'><span style="color: #BFC7D5;">]</span><span style="color: #89DDFF;">)&gt;&lt;/</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">p-4 text-gray-500 bg-red</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;&lt;/</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Likewise, the <code>@style</code> directive may be used to conditionally add inline CSS styles to an HTML element:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #D3423E;">@php</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$isActive</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">=</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">true</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #D3423E;">@endphp</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;"> </span><span style="color: #82AAFF;">@style</span><span style="color: #89DDFF;">(</span><span style="color: #BFC7D5;">[</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">background-color: red</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;">,</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">font-weight: bold</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #BEC5D4;">$isActive</span><span style="color: #89DDFF;">,</span></div><div class='line'><span style="color: #BFC7D5;">]</span><span style="color: #89DDFF;">)&gt;&lt;/</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">style</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">background-color: red; font-weight: bold;</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;&lt;/</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h3 id="additional-attributes"><a href="#additional-attributes">Additional Attributes</a></h3> <p>For convenience, you may use the <code>@checked</code> directive to easily indicate if a given HTML checkbox input is &quot;checked&quot;. This directive will echo <code>checked</code> if the provided condition evaluates to <code>true</code>:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">input</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">checkbox</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">name</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">active</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">value</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">active</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #82AAFF;">@checked</span><span style="color: #89DDFF;">(</span><span style="color: #82AAFF;">old</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">active</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">$</span><span style="color: #BEC5D4;">user</span><span style="color: #89DDFF;">-&gt;active</span><span style="color: #BFC7D5;">)</span><span style="color: #89DDFF;">)</span></div><div class='line'><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>Likewise, the <code>@selected</code> directive may be used to indicate if a given select option should be &quot;selected&quot;:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">select</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">name</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">version</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$product</span><span style="color: #89DDFF;">-&gt;versions</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$version</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">option</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">value</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">{{</span><span style="color: #C3E88D;"> </span><span style="color: #BEC5D4;">$version</span><span style="color: #C3E88D;"> </span><span style="color: #89DDFF;">}}</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #82AAFF;">@selected</span><span style="color: #89DDFF;">(</span><span style="color: #82AAFF;">old</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">version</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span><span style="color: #89DDFF;"> </span><span style="color: #C792EA;">==</span><span style="color: #89DDFF;"> </span><span style="color: #BEC5D4;">$version</span><span style="color: #89DDFF;">)&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$version</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">option</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endforeach</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">select</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Additionally, the <code>@disabled</code> directive may be used to indicate if a given element should be &quot;disabled&quot;:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">submit</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #82AAFF;">@disabled</span><span style="color: #89DDFF;">(</span><span style="color: #BEC5D4;">$errors</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">isNotEmpty</span><span style="color: #BFC7D5;">()</span><span style="color: #89DDFF;">)&gt;</span><span style="color: #BFC7D5;">Submit</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Moreover, the <code>@readonly</code> directive may be used to indicate if a given element should be &quot;readonly&quot;:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">input</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">name</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">value</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e7828a868e8ba78b86958691828bc984888a">[email&#160;protected]</a></span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #82AAFF;">@readonly</span><span style="color: #89DDFF;">(</span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">isNotAdmin</span><span style="color: #BFC7D5;">()</span><span style="color: #89DDFF;">)</span></div><div class='line'><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>In addition, the <code>@required</code> directive may be used to indicate if a given element should be &quot;required&quot;:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">input</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">text</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">name</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">title</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">value</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">title</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #82AAFF;">@required</span><span style="color: #89DDFF;">(</span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">isAdmin</span><span style="color: #BFC7D5;">()</span><span style="color: #89DDFF;">)</span></div><div class='line'><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <h3 id="including-subviews"><a href="#including-subviews">Including Subviews</a></h3> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-purple-600"> <div class="opacity-75"><svg width="28" height="40" viewBox="0 0 28 40" xmlns="http://www.w3.org/2000/svg"><title>lightbulb</title><path d="M12 28h4v-8h-4v8zM8 40h12v-8H8v8zm13.98-14.52c-1.001.705-1.661 1.545-1.98 2.52H8c-.416-.959-1.076-1.799-1.98-2.52A13.99 13.99 0 0 1 0 14C0 6.272 6.272 0 14 0s14 6.272 14 14a13.99 13.99 0 0 1-6.02 11.48z" fill="#FFF" fill-rule="nonzero"/></svg></div> </div> <p class="mb-0 lg:ml-6 callout"> While you're free to use the <code>@include</code> directive, Blade <a href="#components">components</a> provide similar functionality and offer several benefits over the <code>@include</code> directive such as data and attribute binding.</p> </div> <p>Blade's <code>@include</code> directive allows you to include a Blade view from within another view. All variables that are available to the parent view will be made available to the included view:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@include</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">shared.errors</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">form</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> Form Contents </span><span style="color: #697098;">--&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">form</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Even though the included view will inherit all data available in the parent view, you may also pass an array of additional data that should be made available to the included view:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@include</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">view.name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, [</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">status</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">complete</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span></div></code></pre> </div> <p>If you attempt to <code>@include</code> a view which does not exist, Laravel will throw an error. If you would like to include a view that may or may not be present, you should use the <code>@includeIf</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@includeIf</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">view.name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, [</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">status</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">complete</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span></div></code></pre> </div> <p>If you would like to <code>@include</code> a view if a given boolean expression evaluates to <code>true</code> or <code>false</code>, you may use the <code>@includeWhen</code> and <code>@includeUnless</code> directives:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@includeWhen</span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$boolean</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">view.name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, [</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">status</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">complete</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #82AAFF;">@includeUnless</span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$boolean</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">view.name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, [</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">status</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">complete</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span></div></code></pre> </div> <p>To include the first view that exists from a given array of views, you may use the <code>includeFirst</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@includeFirst</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">custom.admin</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">admin</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">], [</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">status</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">complete</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span></div></code></pre> </div> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-red-600"> <div class="opacity-75"><svg width="6" height="35" viewBox="0 0 6 35" xmlns="http://www.w3.org/2000/svg"><title>exclamation</title><path d="M0 29h6v6H0v-6zM0 0h6v24H0V0z" fill="#FFF" fill-rule="nonzero"/></svg> </div> </div> <p class="mb-0 lg:ml-6 callout"> You should avoid using the <code>__DIR__</code> and <code>__FILE__</code> constants in your Blade views, since they will refer to the location of the cached, compiled view.</p> </div> <h4 id="rendering-views-for-collections"><a href="#rendering-views-for-collections">Rendering Views for Collections</a></h4> <p>You may combine loops and includes into one line with Blade's <code>@each</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@each</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">view.name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #BEC5D4;">$jobs</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">job</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div></code></pre> </div> <p>The <code>@each</code> directive's first argument is the view to render for each element in the array or collection. The second argument is the array or collection you wish to iterate over, while the third argument is the variable name that will be assigned to the current iteration within the view. So, for example, if you are iterating over an array of <code>jobs</code>, typically you will want to access each job as a <code>job</code> variable within the view. The array key for the current iteration will be available as the <code>key</code> variable within the view.</p> <p>You may also pass a fourth argument to the <code>@each</code> directive. This argument determines the view that will be rendered if the given array is empty.</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@each</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">view.name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #BEC5D4;">$jobs</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">job</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">view.empty</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div></code></pre> </div> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-red-600"> <div class="opacity-75"><svg width="6" height="35" viewBox="0 0 6 35" xmlns="http://www.w3.org/2000/svg"><title>exclamation</title><path d="M0 29h6v6H0v-6zM0 0h6v24H0V0z" fill="#FFF" fill-rule="nonzero"/></svg> </div> </div> <p class="mb-0 lg:ml-6 callout"> Views rendered via <code>@each</code> do not inherit the variables from the parent view. If the child view requires these variables, you should use the <code>@foreach</code> and <code>@include</code> directives instead.</p> </div> <h3 id="the-once-directive"><a href="#the-once-directive">The <code>@once</code> Directive</a></h3> <p>The <code>@once</code> directive allows you to define a portion of the template that will only be evaluated once per rendering cycle. This may be useful for pushing a given piece of JavaScript into the page's header using <a href="#stacks">stacks</a>. For example, if you are rendering a given <a href="#components">component</a> within a loop, you may wish to only push the JavaScript to the header the first time the component is rendered:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@once</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@push</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">scripts</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">//</span><span style="color: #697098;"> Your custom JavaScript...</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endpush</span></div><div class='line'><span style="color: #C792EA;">@endonce</span></div></code></pre> </div> <p>Since the <code>@once</code> directive is often used in conjunction with the <code>@push</code> or <code>@prepend</code> directives, the <code>@pushOnce</code> and <code>@prependOnce</code> directives are available for your convenience:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@pushOnce</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">scripts</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">//</span><span style="color: #697098;"> Your custom JavaScript...</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endPushOnce</span></div></code></pre> </div> <h3 id="raw-php"><a href="#raw-php">Raw PHP</a></h3> <p>In some situations, it's useful to embed PHP code into your views. You can use the Blade <code>@php</code> directive to execute a block of plain PHP within your template:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #D3423E;">@php</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$counter</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">=</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">1</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #D3423E;">@endphp</span></div></code></pre> </div> <p>Or, if you only need to use PHP to import a class, you may use the <code>@use</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #82AAFF;">@use</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">App\Models\Flight</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div></code></pre> </div> <p>A second argument may be provided to the <code>@use</code> directive to alias the imported class:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">@</span><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;">(&#39;App\Models\</span><span style="color: #FFCB8B;">Flight</span><span style="color: #BFC7D5;">&#39;, &#39;</span><span style="color: #FFCB8B;">FlightModel</span><span style="color: #BFC7D5;">&#39;)</span></div></code></pre> </div> <h3 id="comments"><a href="#comments">Comments</a></h3> <p>Blade also allows you to define comments in your views. However, unlike HTML comments, Blade comments are not included in the HTML returned by your application:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">{{--</span><span style="color: #697098;"> This comment will not be present in the rendered HTML </span><span style="color: #697098;">--}}</span></div></code></pre> </div> <h2 id="components"><a href="#components">Components</a></h2> <p>Components and slots provide similar benefits to sections, layouts, and includes; however, some may find the mental model of components and slots easier to understand. There are two approaches to writing components: class based components and anonymous components.</p> <p>To create a class based component, you may use the <code>make:component</code> Artisan command. To illustrate how to use components, we will create a simple <code>Alert</code> component. The <code>make:component</code> command will place the component in the <code>app/View/Components</code> directory:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="shell" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">php </span><span style="color: #BFC7D5;">artisan</span><span style="color: #BFC7D5;"> </span><span style="color: #BFC7D5;">make:component</span><span style="color: #BFC7D5;"> </span><span style="color: #BFC7D5;">Alert</span></div></code></pre> </div> <p>The <code>make:component</code> command will also create a view template for the component. The view will be placed in the <code>resources/views/components</code> directory. When writing components for your own application, components are automatically discovered within the <code>app/View/Components</code> directory and <code>resources/views/components</code> directory, so no further component registration is typically required.</p> <p>You may also create components within subdirectories:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="shell" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">php </span><span style="color: #BFC7D5;">artisan</span><span style="color: #BFC7D5;"> </span><span style="color: #BFC7D5;">make:component</span><span style="color: #BFC7D5;"> </span><span style="color: #BFC7D5;">Forms/Input</span></div></code></pre> </div> <p>The command above will create an <code>Input</code> component in the <code>app/View/Components/Forms</code> directory and the view will be placed in the <code>resources/views/components/forms</code> directory.</p> <p>If you would like to create an anonymous component (a component with only a Blade template and no class), you may use the <code>--view</code> flag when invoking the <code>make:component</code> command:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="shell" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">php </span><span style="color: #BFC7D5;">artisan</span><span style="color: #BFC7D5;"> </span><span style="color: #BFC7D5;">make:component</span><span style="color: #BFC7D5;"> </span><span style="color: #BFC7D5;">forms.input</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">--view</span></div></code></pre> </div> <p>The command above will create a Blade file at <code>resources/views/components/forms/input.blade.php</code> which can be rendered as a component via <code>&lt;x-forms.input /&gt;</code>.</p> <h4 id="manually-registering-package-components"><a href="#manually-registering-package-components">Manually Registering Package Components</a></h4> <p>When writing components for your own application, components are automatically discovered within the <code>app/View/Components</code> directory and <code>resources/views/components</code> directory.</p> <p>However, if you are building a package that utilizes Blade components, you will need to manually register your component class and its HTML tag alias. You should typically register your components in the <code>boot</code> method of your package's service provider:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\Facades\</span><span style="color: #FFCB8B;">Blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Bootstrap your package&#39;s services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">boot</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">component</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">package-alert</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #FFCB8B;">Alert</span><span style="color: #89DDFF;">::</span><span style="color: #C792EA;">class</span><span style="color: #BFC7D5;">);</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>Once your component has been registered, it may be rendered using its tag alias:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-package-alert</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>Alternatively, you may use the <code>componentNamespace</code> method to autoload component classes by convention. For example, a <code>Nightshade</code> package might have <code>Calendar</code> and <code>ColorPicker</code> components that reside within the <code>Package\Views\Components</code> namespace:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\Facades\</span><span style="color: #FFCB8B;">Blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Bootstrap your package&#39;s services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">boot</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">componentNamespace</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Nightshade</span><span style="color: #F78C6C;">\\</span><span style="color: #C3E88D;">Views</span><span style="color: #F78C6C;">\\</span><span style="color: #C3E88D;">Components</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">nightshade</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">);</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>This will allow the usage of package components by their vendor namespace using the <code>package-name::</code> syntax:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FFFFFF;">x-nightshade::calendar</span><span style="color: #89DDFF;"> /&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FFFFFF;">x-nightshade::color-picker</span><span style="color: #89DDFF;"> /&gt;</span></div></code></pre> </div> <p>Blade will automatically detect the class that's linked to this component by pascal-casing the component name. Subdirectories are also supported using &quot;dot&quot; notation.</p> <h3 id="rendering-components"><a href="#rendering-components">Rendering Components</a></h3> <p>To display a component, you may use a Blade component tag within one of your Blade templates. Blade component tags start with the string <code>x-</code> followed by the kebab case name of the component class:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;">/&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-user-profile</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>If the component class is nested deeper within the <code>app/View/Components</code> directory, you may use the <code>.</code> character to indicate directory nesting. For example, if we assume a component is located at <code>app/View/Components/Inputs/Button.php</code>, we may render it like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-inputs.button</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>If you would like to conditionally render your component, you may define a <code>shouldRender</code> method on your component class. If the <code>shouldRender</code> method returns <code>false</code> the component will not be rendered:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\</span><span style="color: #FFCB8B;">Str</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Whether the component should be rendered</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">shouldRender</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">bool</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Str</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">length</span><span style="color: #BFC7D5;">(</span><span style="color: #FF5572;">$this</span><span style="color: #89DDFF;">-&gt;message</span><span style="color: #BFC7D5;">) </span><span style="color: #C792EA;">&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #F78C6C;">0</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <h3 id="index-components"><a href="#index-components">Index Components</a></h3> <p>Sometimes components are part of a component group and you may wish to group the related components within a single directory. For example, imagine a &quot;card&quot; component with the following class structure:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="none" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">App\Views\Components\Card\Card</span></div><div class='line'><span style="color: #BFC7D5;">App\Views\Components\Card\Header</span></div><div class='line'><span style="color: #BFC7D5;">App\Views\Components\Card\Body</span></div></code></pre> </div> <p>Since the root <code>Card</code> component is nested within a <code>Card</code> directory, you might expect that you would need to render the component via <code>&lt;x-card.card&gt;</code>. However, when a component's file name matches the name of the component's directory, Laravel automatically assumes that component is the &quot;root&quot; component and allows you to render the component without repeating the directory name:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-card</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-card.header</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">...</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-card.header</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-card.body</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">...</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-card.body</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-card</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h3 id="passing-data-to-components"><a href="#passing-data-to-components">Passing Data to Components</a></h3> <p>You may pass data to Blade components using HTML attributes. Hard-coded, primitive values may be passed to the component using simple HTML attribute strings. PHP expressions and variables should be passed to the component via attributes that use the <code>:</code> character as a prefix:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">error</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:message</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">$message</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>You should define all of the component's data attributes in its class constructor. All public properties on a component will automatically be made available to the component's view. It is not necessary to pass the data to the view from the component's <code>render</code> method:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #D3423E;">&lt;?php</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">namespace</span><span style="color: #BFC7D5;"> App\View\Components;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\View\</span><span style="color: #FFCB8B;">Component</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\View\</span><span style="color: #FFCB8B;">View</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">class</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB6B;">Alert</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">extends</span><span style="color: #BFC7D5;"> </span><span style="color: #A9C77D;">Component</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Create the component instance.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">__construct</span><span style="color: #D9F5DD;">(</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">string</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$type</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">string</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$message</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">)</span><span style="color: #BFC7D5;"> {}</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Get the view / contents that represent the component.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">render</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">View</span></div><div class='line'><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">view</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">components.alert</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">);</span></div><div class='line'><span style="color: #BFC7D5;"> }</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>When your component is rendered, you may display the contents of your component's public variables by echoing the variables by name:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">alert alert-</span><span style="color: #89DDFF;">{{</span><span style="color: #C3E88D;"> </span><span style="color: #BEC5D4;">$type</span><span style="color: #C3E88D;"> </span><span style="color: #89DDFF;">}}</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$message</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h4 id="casing"><a href="#casing">Casing</a></h4> <p>Component constructor arguments should be specified using <code>camelCase</code>, while <code>kebab-case</code> should be used when referencing the argument names in your HTML attributes. For example, given the following component constructor:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Create the component instance.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">__construct</span><span style="color: #D9F5DD;">(</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">string</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$alertType</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #D9F5DD;">)</span><span style="color: #BFC7D5;"> {}</span></div></code></pre> <p>The <code>$alertType</code> argument may be provided to the component like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">alert-type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">danger</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> /&gt;</span></div></code></pre> </div> <h4 id="short-attribute-syntax"><a href="#short-attribute-syntax">Short Attribute Syntax</a></h4> <p>When passing attributes to components, you may also use a &quot;short attribute&quot; syntax. This is often convenient since attribute names frequently match the variable names they correspond to:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">{{--</span><span style="color: #697098;"> Short attribute syntax... </span><span style="color: #697098;">--}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-profile</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:$userId</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:$name</span><span style="color: #89DDFF;"> /&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">{{--</span><span style="color: #697098;"> Is equivalent to... </span><span style="color: #697098;">--}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-profile</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:user-id</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">$userId</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:name</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">$name</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> /&gt;</span></div></code></pre> </div> <h4 id="escaping-attribute-rendering"><a href="#escaping-attribute-rendering">Escaping Attribute Rendering</a></h4> <p>Since some JavaScript frameworks such as Alpine.js also use colon-prefixed attributes, you may use a double colon (<code>::</code>) prefix to inform Blade that the attribute is not a PHP expression. For example, given the following component:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-button</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">::class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">{ danger: isDeleting }</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Submit</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-button</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>The following HTML will be rendered by Blade:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">{ danger: isDeleting }</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Submit</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h4 id="component-methods"><a href="#component-methods">Component Methods</a></h4> <p>In addition to public variables being available to your component template, any public methods on the component may be invoked. For example, imagine a component that has an <code>isSelected</code> method:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Determine if the given option is the currently selected option.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">isSelected</span><span style="color: #D9F5DD;">(</span><span style="color: #C792EA;">string</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$option</span><span style="color: #D9F5DD;">)</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">bool</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$option</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">===</span><span style="color: #BFC7D5;"> </span><span style="color: #FF5572;">$this</span><span style="color: #89DDFF;">-&gt;selected</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>You may execute this method from your component template by invoking the variable matching the name of the method:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">option</span><span style="color: #89DDFF;"> {{ </span><span style="color: #82AAFF;">$</span><span style="color: #BEC5D4;">isSelected</span><span style="color: #89DDFF;">(</span><span style="color: #BEC5D4;">$value</span><span style="color: #89DDFF;">) ? </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">selected</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> : </span><span style="color: #D9F5DD;">&#39;&#39;</span><span style="color: #89DDFF;"> }} </span><span style="color: #FFCB6B;">value</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">{{</span><span style="color: #C3E88D;"> </span><span style="color: #BEC5D4;">$value</span><span style="color: #C3E88D;"> </span><span style="color: #89DDFF;">}}</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$label</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">option</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h4 id="using-attributes-slots-within-component-class"><a href="#using-attributes-slots-within-component-class">Accessing Attributes and Slots Within Component Classes</a></h4> <p>Blade components also allow you to access the component name, attributes, and slot inside the class's render method. However, in order to access this data, you should return a closure from your component's <code>render</code> method:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Closure</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Get the view / contents that represent the component.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">render</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Closure</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">()</span><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">&lt;div {{ $attributes }}&gt;Components content&lt;/div&gt;</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #BFC7D5;"> };</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>The closure returned by your component's <code>render</code> method may also receive a <code>$data</code> array as its only argument. This array will contain several elements that provide information about the component:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">(</span><span style="color: #C792EA;">array</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$data</span><span style="color: #D9F5DD;">)</span><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">//</span><span style="color: #697098;"> $data[&#39;componentName&#39;];</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">//</span><span style="color: #697098;"> $data[&#39;attributes&#39;];</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">//</span><span style="color: #697098;"> $data[&#39;slot&#39;];</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">&lt;div {{ $attributes }}&gt;Components content&lt;/div&gt;</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-red-600"> <div class="opacity-75"><svg width="6" height="35" viewBox="0 0 6 35" xmlns="http://www.w3.org/2000/svg"><title>exclamation</title><path d="M0 29h6v6H0v-6zM0 0h6v24H0V0z" fill="#FFF" fill-rule="nonzero"/></svg> </div> </div> <p class="mb-0 lg:ml-6 callout"> The elements in the <code>$data</code> array should never be directly embedded into the Blade string returned by your <code>render</code> method, as doing so could allow remote code execution via malicious attribute content.</p> </div> <p>The <code>componentName</code> is equal to the name used in the HTML tag after the <code>x-</code> prefix. So <code>&lt;x-alert /&gt;</code>'s <code>componentName</code> will be <code>alert</code>. The <code>attributes</code> element will contain all of the attributes that were present on the HTML tag. The <code>slot</code> element is an <code>Illuminate\Support\HtmlString</code> instance with the contents of the component's slot.</p> <p>The closure should return a string. If the returned string corresponds to an existing view, that view will be rendered; otherwise, the returned string will be evaluated as an inline Blade view.</p> <h4 id="additional-dependencies"><a href="#additional-dependencies">Additional Dependencies</a></h4> <p>If your component requires dependencies from Laravel's <a href="/docs/11.x/container">service container</a>, you may list them before any of the component's data attributes and they will automatically be injected by the container:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> App\Services\</span><span style="color: #FFCB8B;">AlertCreator</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Create the component instance.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">__construct</span><span style="color: #D9F5DD;">(</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">AlertCreator</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$creator</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">string</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$type</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">string</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$message</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #D9F5DD;">)</span><span style="color: #BFC7D5;"> {}</span></div></code></pre> </div> <h4 id="hiding-attributes-and-methods"><a href="#hiding-attributes-and-methods">Hiding Attributes / Methods</a></h4> <p>If you would like to prevent some public methods or properties from being exposed as variables to your component template, you may add them to an <code>$except</code> array property on your component:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #D3423E;">&lt;?php</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">namespace</span><span style="color: #BFC7D5;"> App\View\Components;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\View\</span><span style="color: #FFCB8B;">Component</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">class</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB6B;">Alert</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">extends</span><span style="color: #BFC7D5;"> </span><span style="color: #A9C77D;">Component</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * The properties / methods that should not be exposed to the component template.</span></div><div class='line'><span style="color: #697098;"> *</span></div><div class='line'><span style="color: #697098;"> * </span><span style="color: #C792EA;">@var</span><span style="color: #697098;"> </span><span style="color: #C792EA;">array</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">protected</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$except</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">=</span><span style="color: #BFC7D5;"> [</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">type</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">];</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Create the component instance.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">__construct</span><span style="color: #D9F5DD;">(</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">string</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$type</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">)</span><span style="color: #BFC7D5;"> {}</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <h3 id="component-attributes"><a href="#component-attributes">Component Attributes</a></h3> <p>We've already examined how to pass data attributes to a component; however, sometimes you may need to specify additional HTML attributes, such as <code>class</code>, that are not part of the data required for a component to function. Typically, you want to pass these additional attributes down to the root element of the component template. For example, imagine we want to render an <code>alert</code> component like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">error</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:message</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">$message</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">mt-4</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>All of the attributes that are not part of the component's constructor will automatically be added to the component's &quot;attribute bag&quot;. This attribute bag is automatically made available to the component via the <code>$attributes</code> variable. All of the attributes may be rendered within the component by echoing this variable:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> Component content </span><span style="color: #697098;">--&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-red-600"> <div class="opacity-75"><svg width="6" height="35" viewBox="0 0 6 35" xmlns="http://www.w3.org/2000/svg"><title>exclamation</title><path d="M0 29h6v6H0v-6zM0 0h6v24H0V0z" fill="#FFF" fill-rule="nonzero"/></svg> </div> </div> <p class="mb-0 lg:ml-6 callout"> Using directives such as <code>@env</code> within component tags is not supported at this time. For example, <code>&lt;x-alert :live=&quot;@env('production')&quot;/&gt;</code> will not be compiled.</p> </div> <h4 id="default-merged-attributes"><a href="#default-merged-attributes">Default / Merged Attributes</a></h4> <p>Sometimes you may need to specify default values for attributes or merge additional values into some of the component's attributes. To accomplish this, you may use the attribute bag's <code>merge</code> method. This method is particularly useful for defining a set of default CSS classes that should always be applied to a component:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">merge</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">class</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">alert alert-</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;">.</span><span style="color: #BEC5D4;">$type</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$message</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>If we assume this component is utilized like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">error</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:message</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">$message</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">mb-4</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>The final, rendered HTML of the component will appear like the following:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">alert alert-error mb-4</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> Contents of the $message variable </span><span style="color: #697098;">--&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h4 id="conditionally-merge-classes"><a href="#conditionally-merge-classes">Conditionally Merge Classes</a></h4> <p>Sometimes you may wish to merge classes if a given condition is <code>true</code>. You can accomplish this via the <code>class</code> method, which accepts an array of classes where the array key contains the class or classes you wish to add, while the value is a boolean expression. If the array element has a numeric key, it will always be included in the rendered class list:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">class</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">p-4</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">bg-red</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #BEC5D4;">$hasError</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$message</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>If you need to merge other attributes onto your component, you can chain the <code>merge</code> method onto the <code>class</code> method:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">class</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">p-4</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">merge</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">type</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">button</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-purple-600"> <div class="opacity-75"><svg width="28" height="40" viewBox="0 0 28 40" xmlns="http://www.w3.org/2000/svg"><title>lightbulb</title><path d="M12 28h4v-8h-4v8zM8 40h12v-8H8v8zm13.98-14.52c-1.001.705-1.661 1.545-1.98 2.52H8c-.416-.959-1.076-1.799-1.98-2.52A13.99 13.99 0 0 1 0 14C0 6.272 6.272 0 14 0s14 6.272 14 14a13.99 13.99 0 0 1-6.02 11.48z" fill="#FFF" fill-rule="nonzero"/></svg></div> </div> <p class="mb-0 lg:ml-6 callout"> If you need to conditionally compile classes on other HTML elements that shouldn't receive merged attributes, you can use the <a href="#conditional-classes"><code>@class</code> directive</a>.</p> </div> <h4 id="non-class-attribute-merging"><a href="#non-class-attribute-merging">Non-Class Attribute Merging</a></h4> <p>When merging attributes that are not <code>class</code> attributes, the values provided to the <code>merge</code> method will be considered the &quot;default&quot; values of the attribute. However, unlike the <code>class</code> attribute, these attributes will not be merged with injected attribute values. Instead, they will be overwritten. For example, a <code>button</code> component's implementation may look like the following:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">merge</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">type</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">button</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>To render the button component with a custom <code>type</code>, it may be specified when consuming the component. If no type is specified, the <code>button</code> type will be used:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-button</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">submit</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Submit</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-button</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>The rendered HTML of the <code>button</code> component in this example would be:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">submit</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Submit</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">button</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>If you would like an attribute other than <code>class</code> to have its default value and injected values joined together, you may use the <code>prepends</code> method. In this example, the <code>data-controller</code> attribute will always begin with <code>profile-controller</code> and any additional injected <code>data-controller</code> values will be placed after this default value:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">merge</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">data-controller</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">prepends</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">profile-controller</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h4 id="filtering-attributes"><a href="#filtering-attributes">Retrieving and Filtering Attributes</a></h4> <p>You may filter attributes using the <code>filter</code> method. This method accepts a closure which should return <code>true</code> if you wish to retain the attribute in the attribute bag:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">filter</span><span style="color: #BFC7D5;">(</span><span style="color: #82AAFF;">fn </span><span style="color: #BFC7D5;">(</span><span style="color: #C792EA;">string</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">$</span><span style="color: #BEC5D4;">value</span><span style="color: #BFC7D5;">,</span><span style="color: #82AAFF;"> </span><span style="color: #C792EA;">string</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">$</span><span style="color: #BEC5D4;">key</span><span style="color: #BFC7D5;">) </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$key</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">==</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">foo</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">) </span><span style="color: #89DDFF;">}}</span></div></code></pre> </div> <p>For convenience, you may use the <code>whereStartsWith</code> method to retrieve all attributes whose keys begin with a given string:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">whereStartsWith</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">wire:model</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">) </span><span style="color: #89DDFF;">}}</span></div></code></pre> </div> <p>Conversely, the <code>whereDoesntStartWith</code> method may be used to exclude all attributes whose keys begin with a given string:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">whereDoesntStartWith</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">wire:model</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">) </span><span style="color: #89DDFF;">}}</span></div></code></pre> </div> <p>Using the <code>first</code> method, you may render the first attribute in a given attribute bag:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">whereStartsWith</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">wire:model</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">first</span><span style="color: #BFC7D5;">() </span><span style="color: #89DDFF;">}}</span></div></code></pre> </div> <p>If you would like to check if an attribute is present on the component, you may use the <code>has</code> method. This method accepts the attribute name as its only argument and returns a boolean indicating whether or not the attribute is present:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">has</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">class</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">))</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">Class attribute is present</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endif</span></div></code></pre> </div> <p>If an array is passed to the <code>has</code> method, the method will determine if all of the given attributes are present on the component:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">has</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">class</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">]))</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">All of the attributes are present</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endif</span></div></code></pre> </div> <p>The <code>hasAny</code> method may be used to determine if any of the given attributes are present on the component:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">hasAny</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">href</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">:href</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">v-bind:href</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">]))</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">One of the attributes is present</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endif</span></div></code></pre> </div> <p>You may retrieve a specific attribute's value using the <code>get</code> method:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">get</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">class</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">) </span><span style="color: #89DDFF;">}}</span></div></code></pre> </div> <h3 id="reserved-keywords"><a href="#reserved-keywords">Reserved Keywords</a></h3> <p>By default, some keywords are reserved for Blade's internal use in order to render components. The following keywords cannot be defined as public properties or method names within your components:</p> <div class="content-list" markdown="1"> <ul> <li> <code>data</code> </li> <li> <code>render</code> </li> <li> <code>resolveView</code> </li> <li> <code>shouldRender</code> </li> <li> <code>view</code> </li> <li> <code>withAttributes</code> </li> <li> <code>withName</code> </li> </ul> </div> <h3 id="slots"><a href="#slots">Slots</a></h3> <p>You will often need to pass additional content to your component via &quot;slots&quot;. Component slots are rendered by echoing the <code>$slot</code> variable. To explore this concept, let's imagine that an <code>alert</code> component has the following markup:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> /resources/views/components/alert.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">alert alert-danger</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>We may pass content to the <code>slot</code> by injecting content into the component:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">strong</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">Whoops!</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">strong</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;"> Something went wrong!</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Sometimes a component may need to render multiple different slots in different locations within the component. Let's modify our alert component to allow for the injection of a &quot;title&quot; slot:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> /resources/views/components/alert.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">alert-title</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$title</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">alert alert-danger</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>You may define the content of the named slot using the <code>x-slot</code> tag. Any content not within an explicit <code>x-slot</code> tag will be passed to the component in the <code>$slot</code> variable:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="xml" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-slot:title</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Server Error</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-slot</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">strong</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">Whoops!</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">strong</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;"> Something went wrong!</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>You may invoke a slot's <code>isEmpty</code> method to determine if the slot contains content:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">alert-title</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$title</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">span</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">alert alert-danger</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$slot</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">isEmpty</span><span style="color: #BFC7D5;">())</span></div><div class='line'><span style="color: #BFC7D5;"> This is default content if the slot is empty.</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@else</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endif</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Additionally, the <code>hasActualContent</code> method may be used to determine if the slot contains any &quot;actual&quot; content that is not an HTML comment:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@if </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$slot</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">hasActualContent</span><span style="color: #BFC7D5;">())</span></div><div class='line'><span style="color: #BFC7D5;"> The scope has non-comment content.</span></div><div class='line'><span style="color: #C792EA;">@endif</span></div></code></pre> </div> <h4 id="scoped-slots"><a href="#scoped-slots">Scoped Slots</a></h4> <p>If you have used a JavaScript framework such as Vue, you may be familiar with &quot;scoped slots&quot;, which allow you to access data or methods from the component within your slot. You may achieve similar behavior in Laravel by defining public methods or properties on your component and accessing the component within your slot via the <code>$component</code> variable. In this example, we will assume that the <code>x-alert</code> component has a public <code>formatAlert</code> method defined on its component class:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FFFFFF;">x-slot:title</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$component</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">formatAlert</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Server Error</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">) </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-slot</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">strong</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">Whoops!</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">strong</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;"> Something went wrong!</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h4 id="slot-attributes"><a href="#slot-attributes">Slot Attributes</a></h4> <p>Like Blade components, you may assign additional <a href="#component-attributes">attributes</a> to slots such as CSS class names:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="xml" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-card</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">shadow-sm</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-slot:heading</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">font-bold</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Heading</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-slot</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> Content</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-slot:footer</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">text-sm</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Footer</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-slot</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-card</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>To interact with slot attributes, you may access the <code>attributes</code> property of the slot's variable. For more information on how to interact with attributes, please consult the documentation on <a href="#component-attributes">component attributes</a>:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #82AAFF;">@props</span><span style="color: #BFC7D5;">([</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">heading</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">footer</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #BFC7D5;">])</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">class</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">border</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">h1</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$heading</span><span style="color: #89DDFF;">-&gt;attributes-&gt;</span><span style="color: #82AAFF;">class</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">text-lg</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$heading</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">h1</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">footer</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$footer</span><span style="color: #89DDFF;">-&gt;attributes-&gt;</span><span style="color: #82AAFF;">class</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">text-gray-700</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$footer</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">footer</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h3 id="inline-component-views"><a href="#inline-component-views">Inline Component Views</a></h3> <p>For very small components, it may feel cumbersome to manage both the component class and the component's view template. For this reason, you may return the component's markup directly from the <code>render</code> method:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Get the view / contents that represent the component.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">render</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">string</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&lt;&lt;&lt;</span><span style="color: #BFC7D5;">&#39;</span><span style="color: #89DDFF;">blade</span><span style="color: #BFC7D5;">&#39;</span></div><div class='line'><span style="color: #BFC7D5;"> &lt;div class=&quot;alert alert-danger&quot;&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> {{ $slot }}</span></div><div class='line'><span style="color: #BFC7D5;"> &lt;/div&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <h4 id="generating-inline-view-components"><a href="#generating-inline-view-components">Generating Inline View Components</a></h4> <p>To create a component that renders an inline view, you may use the <code>inline</code> option when executing the <code>make:component</code> command:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="shell" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">php </span><span style="color: #BFC7D5;">artisan</span><span style="color: #BFC7D5;"> </span><span style="color: #BFC7D5;">make:component</span><span style="color: #BFC7D5;"> </span><span style="color: #BFC7D5;">Alert</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">--inline</span></div></code></pre> </div> <h3 id="dynamic-components"><a href="#dynamic-components">Dynamic Components</a></h3> <p>Sometimes you may need to render a component but not know which component should be rendered until runtime. In this situation, you may use Laravel's built-in <code>dynamic-component</code> component to render the component based on a runtime value or variable:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">// $componentName = &quot;secondary-button&quot;;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-dynamic-component</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:component</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">$componentName</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">mt-4</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> /&gt;</span></div></code></pre> </div> <h3 id="manually-registering-components"><a href="#manually-registering-components">Manually Registering Components</a></h3> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-red-600"> <div class="opacity-75"><svg width="6" height="35" viewBox="0 0 6 35" xmlns="http://www.w3.org/2000/svg"><title>exclamation</title><path d="M0 29h6v6H0v-6zM0 0h6v24H0V0z" fill="#FFF" fill-rule="nonzero"/></svg> </div> </div> <p class="mb-0 lg:ml-6 callout"> The following documentation on manually registering components is primarily applicable to those who are writing Laravel packages that include view components. If you are not writing a package, this portion of the component documentation may not be relevant to you.</p> </div> <p>When writing components for your own application, components are automatically discovered within the <code>app/View/Components</code> directory and <code>resources/views/components</code> directory.</p> <p>However, if you are building a package that utilizes Blade components or placing components in non-conventional directories, you will need to manually register your component class and its HTML tag alias so that Laravel knows where to find the component. You should typically register your components in the <code>boot</code> method of your package's service provider:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\Facades\</span><span style="color: #FFCB8B;">Blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> VendorPackage\View\Components\</span><span style="color: #FFCB8B;">AlertComponent</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Bootstrap your package&#39;s services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">boot</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">component</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">package-alert</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #FFCB8B;">AlertComponent</span><span style="color: #89DDFF;">::</span><span style="color: #C792EA;">class</span><span style="color: #BFC7D5;">);</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>Once your component has been registered, it may be rendered using its tag alias:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-package-alert</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <h4>Autoloading Package Components</h4> <p>Alternatively, you may use the <code>componentNamespace</code> method to autoload component classes by convention. For example, a <code>Nightshade</code> package might have <code>Calendar</code> and <code>ColorPicker</code> components that reside within the <code>Package\Views\Components</code> namespace:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\Facades\</span><span style="color: #FFCB8B;">Blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Bootstrap your package&#39;s services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">boot</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">componentNamespace</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Nightshade</span><span style="color: #F78C6C;">\\</span><span style="color: #C3E88D;">Views</span><span style="color: #F78C6C;">\\</span><span style="color: #C3E88D;">Components</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">nightshade</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">);</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>This will allow the usage of package components by their vendor namespace using the <code>package-name::</code> syntax:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FFFFFF;">x-nightshade::calendar</span><span style="color: #89DDFF;"> /&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FFFFFF;">x-nightshade::color-picker</span><span style="color: #89DDFF;"> /&gt;</span></div></code></pre> </div> <p>Blade will automatically detect the class that's linked to this component by pascal-casing the component name. Subdirectories are also supported using &quot;dot&quot; notation.</p> <h2 id="anonymous-components"><a href="#anonymous-components">Anonymous Components</a></h2> <p>Similar to inline components, anonymous components provide a mechanism for managing a component via a single file. However, anonymous components utilize a single view file and have no associated class. To define an anonymous component, you only need to place a Blade template within your <code>resources/views/components</code> directory. For example, assuming you have defined a component at <code>resources/views/components/alert.blade.php</code>, you may simply render it like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>You may use the <code>.</code> character to indicate if a component is nested deeper inside the <code>components</code> directory. For example, assuming the component is defined at <code>resources/views/components/inputs/button.blade.php</code>, you may render it like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-inputs.button</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <h3 id="anonymous-index-components"><a href="#anonymous-index-components">Anonymous Index Components</a></h3> <p>Sometimes, when a component is made up of many Blade templates, you may wish to group the given component's templates within a single directory. For example, imagine an &quot;accordion&quot; component with the following directory structure:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="none" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">/resources/views/components/accordion.blade.php</span></div><div class='line'><span style="color: #BFC7D5;">/resources/views/components/accordion/item.blade.php</span></div></code></pre> </div> <p>This directory structure allows you to render the accordion component and its item like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-accordion</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-accordion.item</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> ...</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-accordion.item</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-accordion</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>However, in order to render the accordion component via <code>x-accordion</code>, we were forced to place the &quot;index&quot; accordion component template in the <code>resources/views/components</code> directory instead of nesting it within the <code>accordion</code> directory with the other accordion related templates.</p> <p>Thankfully, Blade allows you to place a file matching the component's directory name within the component's directory itself. When this template exists, it can be rendered as the &quot;root&quot; element of the component even though it is nested within a directory. So, we can continue to use the same Blade syntax given in the example above; however, we will adjust our directory structure like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="none" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">/resources/views/components/accordion/accordion.blade.php</span></div><div class='line'><span style="color: #BFC7D5;">/resources/views/components/accordion/item.blade.php</span></div></code></pre> </div> <h3 id="data-properties-attributes"><a href="#data-properties-attributes">Data Properties / Attributes</a></h3> <p>Since anonymous components do not have any associated class, you may wonder how you may differentiate which data should be passed to the component as variables and which attributes should be placed in the component's <a href="#component-attributes">attribute bag</a>.</p> <p>You may specify which attributes should be considered data variables using the <code>@props</code> directive at the top of your component's Blade template. All other attributes on the component will be available via the component's attribute bag. If you wish to give a data variable a default value, you may specify the variable's name as the array key and the default value as the array value:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> /resources/views/components/alert.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #82AAFF;">@props</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">type</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">info</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">message</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">merge</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">class</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">alert alert-</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;">.</span><span style="color: #BEC5D4;">$type</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$message</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Given the component definition above, we may render the component like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-alert</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">error</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">:message</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">$message</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">mb-4</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <h3 id="accessing-parent-data"><a href="#accessing-parent-data">Accessing Parent Data</a></h3> <p>Sometimes you may want to access data from a parent component inside a child component. In these cases, you may use the <code>@aware</code> directive. For example, imagine we are building a complex menu component consisting of a parent <code>&lt;x-menu&gt;</code> and child <code>&lt;x-menu.item&gt;</code>:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-menu</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">color</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">purple</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-menu.item</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">...</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-menu.item</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-menu.item</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">...</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-menu.item</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-menu</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>The <code>&lt;x-menu&gt;</code> component may have an implementation like the following:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> /resources/views/components/menu/index.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #82AAFF;">@props</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">color</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">gray</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">ul</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">merge</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">class</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">bg-</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;">.</span><span style="color: #BEC5D4;">$color</span><span style="color: #89DDFF;">.</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">-200</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">ul</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Because the <code>color</code> prop was only passed into the parent (<code>&lt;x-menu&gt;</code>), it won't be available inside <code>&lt;x-menu.item&gt;</code>. However, if we use the <code>@aware</code> directive, we can make it available inside <code>&lt;x-menu.item&gt;</code> as well:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> /resources/views/components/menu/item.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #82AAFF;">@aware</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">color</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">gray</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;"> {{ </span><span style="color: #BEC5D4;">$attributes</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">merge</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">class</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;"> =&gt; </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">text-</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #89DDFF;">.</span><span style="color: #BEC5D4;">$color</span><span style="color: #89DDFF;">.</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">-800</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;"> }}&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-red-600"> <div class="opacity-75"><svg width="6" height="35" viewBox="0 0 6 35" xmlns="http://www.w3.org/2000/svg"><title>exclamation</title><path d="M0 29h6v6H0v-6zM0 0h6v24H0V0z" fill="#FFF" fill-rule="nonzero"/></svg> </div> </div> <p class="mb-0 lg:ml-6 callout"> The <code>@aware</code> directive cannot access parent data that is not explicitly passed to the parent component via HTML attributes. Default <code>@props</code> values that are not explicitly passed to the parent component cannot be accessed by the <code>@aware</code> directive.</p> </div> <h3 id="anonymous-component-paths"><a href="#anonymous-component-paths">Anonymous Component Paths</a></h3> <p>As previously discussed, anonymous components are typically defined by placing a Blade template within your <code>resources/views/components</code> directory. However, you may occasionally want to register other anonymous component paths with Laravel in addition to the default path.</p> <p>The <code>anonymousComponentPath</code> method accepts the &quot;path&quot; to the anonymous component location as its first argument and an optional &quot;namespace&quot; that components should be placed under as its second argument. Typically, this method should be called from the <code>boot</code> method of one of your application's <a href="/docs/11.x/providers">service providers</a>:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Bootstrap any application services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">boot</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">anonymousComponentPath</span><span style="color: #BFC7D5;">(</span><span style="color: #82AAFF;">__DIR__</span><span style="color: #89DDFF;">.</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">/../components</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">);</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>When component paths are registered without a specified prefix as in the example above, they may be rendered in your Blade components without a corresponding prefix as well. For example, if a <code>panel.blade.php</code> component exists in the path registered above, it may be rendered like so:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-panel</span><span style="color: #89DDFF;"> /&gt;</span></div></code></pre> </div> <p>Prefix &quot;namespaces&quot; may be provided as the second argument to the <code>anonymousComponentPath</code> method:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">anonymousComponentPath</span><span style="color: #BFC7D5;">(</span><span style="color: #82AAFF;">__DIR__</span><span style="color: #89DDFF;">.</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">/../components</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">dashboard</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">);</span></div></code></pre> <p>When a prefix is provided, components within that &quot;namespace&quot; may be rendered by prefixing to the component's namespace to the component name when the component is rendered:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FFFFFF;">x-dashboard::panel</span><span style="color: #89DDFF;"> /&gt;</span></div></code></pre> </div> <h2 id="building-layouts"><a href="#building-layouts">Building Layouts</a></h2> <h3 id="layouts-using-components"><a href="#layouts-using-components">Layouts Using Components</a></h3> <p>Most web applications maintain the same general layout across various pages. It would be incredibly cumbersome and hard to maintain our application if we had to repeat the entire layout HTML in every view we create. Thankfully, it's convenient to define this layout as a single <a href="#components">Blade component</a> and then use it throughout our application.</p> <h4 id="defining-the-layout-component"><a href="#defining-the-layout-component">Defining the Layout Component</a></h4> <p>For example, imagine we are building a &quot;todo&quot; list application. We might define a <code>layout</code> component that looks like the following:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> resources/views/components/layout.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">html</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">head</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">title</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$title</span><span style="color: #BFC7D5;"> ?? </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Todo Manager</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">title</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">head</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">body</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">h1</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">Todos</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">h1</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">hr</span><span style="color: #89DDFF;">/&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$slot</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">body</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">html</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h4 id="applying-the-layout-component"><a href="#applying-the-layout-component">Applying the Layout Component</a></h4> <p>Once the <code>layout</code> component has been defined, we may create a Blade view that utilizes the component. In this example, we will define a simple view that displays our task list:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> resources/views/tasks.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-layout</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$tasks</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$task</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$task</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endforeach</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-layout</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Remember, content that is injected into a component will be supplied to the default <code>$slot</code> variable within our <code>layout</code> component. As you may have noticed, our <code>layout</code> also respects a <code>$title</code> slot if one is provided; otherwise, a default title is shown. We may inject a custom title from our task list view using the standard slot syntax discussed in the <a href="#components">component documentation</a>:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> resources/views/tasks.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">x-layout</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FFFFFF;">x-slot:title</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Custom Title</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-slot</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$tasks</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$task</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$task</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endforeach</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">x-layout</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>Now that we have defined our layout and task list views, we just need to return the <code>task</code> view from a route:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> App\Models\</span><span style="color: #FFCB8B;">Task</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #FFCB8B;">Route</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">get</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">/tasks</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">()</span><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">view</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">tasks</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">[</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">tasks</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #82AAFF;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #82AAFF;"> </span><span style="color: #FFCB8B;">Task</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">all</span><span style="color: #BFC7D5;">()]);</span></div><div class='line'><span style="color: #BFC7D5;">});</span></div></code></pre> <h3 id="layouts-using-template-inheritance"><a href="#layouts-using-template-inheritance">Layouts Using Template Inheritance</a></h3> <h4 id="defining-a-layout"><a href="#defining-a-layout">Defining a Layout</a></h4> <p>Layouts may also be created via &quot;template inheritance&quot;. This was the primary way of building applications prior to the introduction of <a href="#components">components</a>.</p> <p>To get started, let's take a look at a simple example. First, we will examine a page layout. Since most web applications maintain the same general layout across various pages, it's convenient to define this layout as a single Blade view:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> resources/views/layouts/app.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">html</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">head</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">title</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">App Name - </span><span style="color: #C792EA;">@yield</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">title</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">title</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">head</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">body</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@section</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">sidebar</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> This is the master sidebar.</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@show</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">container</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@yield</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">content</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">body</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">html</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>As you can see, this file contains typical HTML mark-up. However, take note of the <code>@section</code> and <code>@yield</code> directives. The <code>@section</code> directive, as the name implies, defines a section of content, while the <code>@yield</code> directive is used to display the contents of a given section.</p> <p>Now that we have defined a layout for our application, let's define a child page that inherits the layout.</p> <h4 id="extending-a-layout"><a href="#extending-a-layout">Extending a Layout</a></h4> <p>When defining a child view, use the <code>@extends</code> Blade directive to specify which layout the child view should &quot;inherit&quot;. Views which extend a Blade layout may inject content into the layout's sections using <code>@section</code> directives. Remember, as seen in the example above, the contents of these sections will be displayed in the layout using <code>@yield</code>:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> resources/views/child.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@extends</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">layouts.app</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@section</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">title</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Page Title</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@section</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">sidebar</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> @parent</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">This is appended to the master sidebar.</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endsection</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@section</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">content</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">This is my body content.</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">p</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endsection</span></div></code></pre> </div> <p>In this example, the <code>sidebar</code> section is utilizing the <code>@parent</code> directive to append (rather than overwriting) content to the layout's sidebar. The <code>@parent</code> directive will be replaced by the content of the layout when the view is rendered.</p> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-purple-600"> <div class="opacity-75"><svg width="28" height="40" viewBox="0 0 28 40" xmlns="http://www.w3.org/2000/svg"><title>lightbulb</title><path d="M12 28h4v-8h-4v8zM8 40h12v-8H8v8zm13.98-14.52c-1.001.705-1.661 1.545-1.98 2.52H8c-.416-.959-1.076-1.799-1.98-2.52A13.99 13.99 0 0 1 0 14C0 6.272 6.272 0 14 0s14 6.272 14 14a13.99 13.99 0 0 1-6.02 11.48z" fill="#FFF" fill-rule="nonzero"/></svg></div> </div> <p class="mb-0 lg:ml-6 callout"> Contrary to the previous example, this <code>sidebar</code> section ends with <code>@endsection</code> instead of <code>@show</code>. The <code>@endsection</code> directive will only define a section while <code>@show</code> will define and <strong>immediately yield</strong> the section.</p> </div> <p>The <code>@yield</code> directive also accepts a default value as its second parameter. This value will be rendered if the section being yielded is undefined:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@yield</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">content</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Default content</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div></code></pre> </div> <h2 id="forms"><a href="#forms">Forms</a></h2> <h3 id="csrf-field"><a href="#csrf-field">CSRF Field</a></h3> <p>Anytime you define an HTML form in your application, you should include a hidden CSRF token field in the form so that <a href="/docs/11.x/csrf">the CSRF protection</a> middleware can validate the request. You may use the <code>@csrf</code> Blade directive to generate the token field:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">form</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">method</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">POST</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">action</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">/profile</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@csrf</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> ...</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">form</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h3 id="method-field"><a href="#method-field">Method Field</a></h3> <p>Since HTML forms can't make <code>PUT</code>, <code>PATCH</code>, or <code>DELETE</code> requests, you will need to add a hidden <code>_method</code> field to spoof these HTTP verbs. The <code>@method</code> Blade directive can create this field for you:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">form</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">action</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">/foo/bar</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">method</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">POST</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@method</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">PUT</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> ...</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">form</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h3 id="validation-errors"><a href="#validation-errors">Validation Errors</a></h3> <p>The <code>@error</code> directive may be used to quickly check if <a href="/docs/11.x/validation#quick-displaying-the-validation-errors">validation error messages</a> exist for a given attribute. Within an <code>@error</code> directive, you may echo the <code>$message</code> variable to display the error message:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> /resources/views/post/create.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">label</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">for</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">title</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">Post Title</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">label</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">input</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">id</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">title</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">text</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C792EA;">@error</span><span style="color: #C3E88D;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">title</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">) is-invalid </span><span style="color: #C792EA;">@enderror</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;">/&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@error</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">title</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">alert alert-danger</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$message</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@enderror</span></div></code></pre> </div> <p>Since the <code>@error</code> directive compiles to an &quot;if&quot; statement, you may use the <code>@else</code> directive to render content when there is not an error for an attribute:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> /resources/views/auth.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">label</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">for</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">Email address</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">label</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">input</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">id</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C792EA;">@error</span><span style="color: #C3E88D;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">) is-invalid </span><span style="color: #C792EA;">@else</span><span style="color: #C3E88D;"> is-valid </span><span style="color: #C792EA;">@enderror</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;">/&gt;</span></div></code></pre> </div> <p>You may pass <a href="/docs/11.x/validation#named-error-bags">the name of a specific error bag</a> as the second parameter to the <code>@error</code> directive to retrieve validation error messages on pages containing multiple forms:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> /resources/views/auth.blade.php </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">label</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">for</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;</span><span style="color: #BFC7D5;">Email address</span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">label</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">input</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">id</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">type</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C792EA;">@error</span><span style="color: #C3E88D;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">login</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">) is-invalid </span><span style="color: #C792EA;">@enderror</span><span style="color: #D9F5DD;">&quot;</span></div><div class='line'><span style="color: #89DDFF;">/&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@error</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">email</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">login</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">class</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">alert alert-danger</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$message</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@enderror</span></div></code></pre> </div> <h2 id="stacks"><a href="#stacks">Stacks</a></h2> <p>Blade allows you to push to named stacks which can be rendered somewhere else in another view or layout. This can be particularly useful for specifying any JavaScript libraries required by your child views:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@push</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">scripts</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">src</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">/example.js</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;&lt;/</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #C792EA;">@endpush</span></div></code></pre> </div> <p>If you would like to <code>@push</code> content if a given boolean expression evaluates to <code>true</code>, you may use the <code>@pushIf</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #82AAFF;">@pushIf</span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$shouldPush</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">scripts</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;"> </span><span style="color: #FFCB6B;">src</span><span style="color: #89DDFF;">=</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">/example.js</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #89DDFF;">&gt;&lt;/</span><span style="color: #FF5572;">script</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #82AAFF;">@endPushIf</span></div></code></pre> </div> <p>You may push to a stack as many times as needed. To render the complete stack contents, pass the name of the stack to the <code>@stack</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">head</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> Head Contents </span><span style="color: #697098;">--&gt;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@stack</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">scripts</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">head</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <p>If you would like to prepend content onto the beginning of a stack, you should use the <code>@prepend</code> directive:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@push</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">scripts</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> This will be second...</span></div><div class='line'><span style="color: #C792EA;">@endpush</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;">// Later...</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">@prepend</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">scripts</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> This will be first...</span></div><div class='line'><span style="color: #C792EA;">@endprepend</span></div></code></pre> </div> <h2 id="service-injection"><a href="#service-injection">Service Injection</a></h2> <p>The <code>@inject</code> directive may be used to retrieve a service from the Laravel <a href="/docs/11.x/container">service container</a>. The first argument passed to <code>@inject</code> is the name of the variable the service will be placed into, while the second argument is the class or interface name of the service you wish to resolve:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">@inject</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">metrics</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">App\Services\MetricsService</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> Monthly Revenue: </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$metrics</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">monthlyRevenue</span><span style="color: #BFC7D5;">() </span><span style="color: #89DDFF;">}}</span><span style="color: #BFC7D5;">.</span></div><div class='line'><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">div</span><span style="color: #89DDFF;">&gt;</span></div></code></pre> </div> <h2 id="rendering-inline-blade-templates"><a href="#rendering-inline-blade-templates">Rendering Inline Blade Templates</a></h2> <p>Sometimes you may need to transform a raw Blade template string into valid HTML. You may accomplish this using the <code>render</code> method provided by the <code>Blade</code> facade. The <code>render</code> method accepts the Blade template string and an optional array of data to provide to the template:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\Facades\</span><span style="color: #FFCB8B;">Blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">render</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Hello, {{ $name }}</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, [</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Julian Bashir</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">]);</span></div></code></pre> </div> <p>Laravel renders inline Blade templates by writing them to the <code>storage/framework/views</code> directory. If you would like Laravel to remove these temporary files after rendering the Blade template, you may provide the <code>deleteCachedView</code> argument to the method:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">render</span><span style="color: #BFC7D5;">(</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Hello, {{ $name }}</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span></div><div class='line'><span style="color: #BFC7D5;"> [</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">name</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">Julian Bashir</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">],</span></div><div class='line'><span style="color: #BFC7D5;"> deleteCachedView: </span><span style="color: #82AAFF;">true</span></div><div class='line'><span style="color: #BFC7D5;">);</span></div></code></pre> </div> <h2 id="rendering-blade-fragments"><a href="#rendering-blade-fragments">Rendering Blade Fragments</a></h2> <p>When using frontend frameworks such as <a href="https://turbo.hotwired.dev/">Turbo</a> and <a href="https://htmx.org/">htmx</a>, you may occasionally need to only return a portion of a Blade template within your HTTP response. Blade &quot;fragments&quot; allow you to do just that. To get started, place a portion of your Blade template within <code>@fragment</code> and <code>@endfragment</code> directives:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #82AAFF;">@fragment</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">user-list</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">ul</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@foreach </span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$users</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">as</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;">&gt;{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$user</span><span style="color: #89DDFF;">-&gt;name</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}&lt;/</span><span style="color: #FF5572;">li</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">@endforeach</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">&lt;/</span><span style="color: #FF5572;">ul</span><span style="color: #89DDFF;">&gt;</span></div><div class='line'><span style="color: #82AAFF;">@endfragment</span></div></code></pre> </div> <p>Then, when rendering the view that utilizes this template, you may invoke the <code>fragment</code> method to specify that only the specified fragment should be included in the outgoing HTTP response:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">view</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">dashboard</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">[</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">users</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #82AAFF;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">$</span><span style="color: #BEC5D4;">users</span><span style="color: #BFC7D5;">])</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">fragment</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">user-list</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">);</span></div></code></pre> </div> <p>The <code>fragmentIf</code> method allows you to conditionally return a fragment of a view based on a given condition. Otherwise, the entire view will be returned:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">view</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">dashboard</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">[</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">users</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #82AAFF;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">$</span><span style="color: #BEC5D4;">users</span><span style="color: #BFC7D5;">])</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">fragmentIf</span><span style="color: #BFC7D5;">(</span><span style="color: #BEC5D4;">$request</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">hasHeader</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">HX-Request</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">), </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">user-list</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">);</span></div></code></pre> </div> <p>The <code>fragments</code> and <code>fragmentsIf</code> methods allow you to return multiple view fragments in the response. The fragments will be concatenated together:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #82AAFF;">view</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">dashboard</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">[</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">users</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #82AAFF;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">$</span><span style="color: #BEC5D4;">users</span><span style="color: #BFC7D5;">])</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">fragments</span><span style="color: #BFC7D5;">([</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">user-list</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">comment-list</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">]);</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #82AAFF;">view</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">dashboard</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">,</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">[</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">users</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #82AAFF;"> </span><span style="color: #89DDFF;">=&gt;</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">$</span><span style="color: #BEC5D4;">users</span><span style="color: #BFC7D5;">])</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">fragmentsIf</span><span style="color: #BFC7D5;">(</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$request</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">hasHeader</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">HX-Request</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">),</span></div><div class='line'><span style="color: #BFC7D5;"> [</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">user-list</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">comment-list</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">]</span></div><div class='line'><span style="color: #BFC7D5;"> );</span></div></code></pre> </div> <h2 id="extending-blade"><a href="#extending-blade">Extending Blade</a></h2> <p>Blade allows you to define your own custom directives using the <code>directive</code> method. When the Blade compiler encounters the custom directive, it will call the provided callback with the expression that the directive contains.</p> <p>The following example creates a <code>@datetime($var)</code> directive which formats a given <code>$var</code>, which should be an instance of <code>DateTime</code>:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #D3423E;">&lt;?php</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">namespace</span><span style="color: #BFC7D5;"> App\Providers;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\Facades\</span><span style="color: #FFCB8B;">Blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\</span><span style="color: #FFCB8B;">ServiceProvider</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #C792EA;">class</span><span style="color: #BFC7D5;"> </span><span style="color: #FFCB6B;">AppServiceProvider</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">extends</span><span style="color: #BFC7D5;"> </span><span style="color: #A9C77D;">ServiceProvider</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Register any application services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">register</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">//</span><span style="color: #697098;"> ...</span></div><div class='line'><span style="color: #BFC7D5;"> }</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Bootstrap any application services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">boot</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">directive</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">datetime</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">(</span><span style="color: #C792EA;">string</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$expression</span><span style="color: #D9F5DD;">)</span><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">&quot;</span><span style="color: #C3E88D;">&lt;?php echo (</span><span style="color: #BEC5D4;">$expression</span><span style="color: #C3E88D;">)-&gt;format(&#39;m/d/Y H:i&#39;); ?&gt;</span><span style="color: #D9F5DD;">&quot;</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #BFC7D5;"> });</span></div><div class='line'><span style="color: #BFC7D5;"> }</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>As you can see, we will chain the <code>format</code> method onto whatever expression is passed into the directive. So, in this example, the final PHP generated by this directive will be:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #D3423E;">&lt;?php</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">echo</span><span style="color: #82AAFF;"> </span><span style="color: #BFC7D5;">($</span><span style="color: #BEC5D4;">var</span><span style="color: #BFC7D5;">)</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">format</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">m/d/Y H:i</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">); </span><span style="color: #D3423E;">?&gt;</span></div></code></pre> <div class="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center callout"> <div class="w-20 h-20 mb-6 flex items-center justify-center shrink-0 lg:mb-0 bg-red-600"> <div class="opacity-75"><svg width="6" height="35" viewBox="0 0 6 35" xmlns="http://www.w3.org/2000/svg"><title>exclamation</title><path d="M0 29h6v6H0v-6zM0 0h6v24H0V0z" fill="#FFF" fill-rule="nonzero"/></svg> </div> </div> <p class="mb-0 lg:ml-6 callout"> After updating the logic of a Blade directive, you will need to delete all of the cached Blade views. The cached Blade views may be removed using the <code>view:clear</code> Artisan command.</p> </div> <h3 id="custom-echo-handlers"><a href="#custom-echo-handlers">Custom Echo Handlers</a></h3> <p>If you attempt to &quot;echo&quot; an object using Blade, the object's <code>__toString</code> method will be invoked. The <a href="https://www.php.net/manual/en/language.oop5.magic.php#object.tostring"><code>__toString</code></a> method is one of PHP's built-in &quot;magic methods&quot;. However, sometimes you may not have control over the <code>__toString</code> method of a given class, such as when the class that you are interacting with belongs to a third-party library.</p> <p>In these cases, Blade allows you to register a custom echo handler for that particular type of object. To accomplish this, you should invoke Blade's <code>stringable</code> method. The <code>stringable</code> method accepts a closure. This closure should type-hint the type of object that it is responsible for rendering. Typically, the <code>stringable</code> method should be invoked within the <code>boot</code> method of your application's <code>AppServiceProvider</code> class:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\Facades\</span><span style="color: #FFCB8B;">Blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Money\</span><span style="color: #FFCB8B;">Money</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Bootstrap any application services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">boot</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">stringable</span><span style="color: #BFC7D5;">(</span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">(</span><span style="color: #FFCB8B;">Money</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$money</span><span style="color: #D9F5DD;">)</span><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$money</span><span style="color: #89DDFF;">-&gt;</span><span style="color: #82AAFF;">formatTo</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">en_GB</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">);</span></div><div class='line'><span style="color: #BFC7D5;"> });</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>Once your custom echo handler has been defined, you may simply echo the object in your Blade template:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #BFC7D5;">Cost: </span><span style="color: #89DDFF;">{{</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$money</span><span style="color: #BFC7D5;"> </span><span style="color: #89DDFF;">}}</span></div></code></pre> </div> <h3 id="custom-if-statements"><a href="#custom-if-statements">Custom If Statements</a></h3> <p>Programming a custom directive is sometimes more complex than necessary when defining simple, custom conditional statements. For that reason, Blade provides a <code>Blade::if</code> method which allows you to quickly define custom conditional directives using closures. For example, let's define a custom conditional that checks the configured default &quot;disk&quot; for the application. We may do this in the <code>boot</code> method of our <code>AppServiceProvider</code>:</p> <pre><code data-theme="olaolu-palenight" data-lang="php" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #C792EA;">use</span><span style="color: #BFC7D5;"> Illuminate\Support\Facades\</span><span style="color: #FFCB8B;">Blade</span><span style="color: #BFC7D5;">;</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #697098;">/**</span></div><div class='line'><span style="color: #697098;"> * Bootstrap any application services.</span></div><div class='line'><span style="color: #697098;"> </span><span style="color: #697098;">*/</span></div><div class='line'><span style="color: #C792EA;">public</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">boot</span><span style="color: #D9F5DD;">()</span><span style="color: #89DDFF;">:</span><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">void</span></div><div class='line'><span style="color: #BFC7D5;">{</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #FFCB8B;">Blade</span><span style="color: #89DDFF;">::</span><span style="color: #82AAFF;">if</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">disk</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">, </span><span style="color: #C792EA;">function</span><span style="color: #BFC7D5;"> </span><span style="color: #D9F5DD;">(</span><span style="color: #C792EA;">string</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$value</span><span style="color: #D9F5DD;">)</span><span style="color: #BFC7D5;"> {</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #C792EA;">return</span><span style="color: #BFC7D5;"> </span><span style="color: #82AAFF;">config</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">filesystems.default</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">) </span><span style="color: #C792EA;">===</span><span style="color: #BFC7D5;"> </span><span style="color: #BEC5D4;">$value</span><span style="color: #BFC7D5;">;</span></div><div class='line'><span style="color: #BFC7D5;"> });</span></div><div class='line'><span style="color: #BFC7D5;">}</span></div></code></pre> <p>Once the custom conditional has been defined, you can use it within your templates:</p> <div class="code-container"> <pre><code data-theme="olaolu-palenight" data-lang="blade" class='torchlight' style='background-color: #292D3E; --theme-selection-background: #7580B850;'><!-- Syntax highlighted by torchlight.dev --><div class='line'><span style="color: #82AAFF;">@disk</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">local</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> The application is using the local disk... </span><span style="color: #697098;">--&gt;</span></div><div class='line'><span style="color: #82AAFF;">@elsedisk</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">s3</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> The application is using the s3 disk... </span><span style="color: #697098;">--&gt;</span></div><div class='line'><span style="color: #C792EA;">@else</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> The application is using some other disk... </span><span style="color: #697098;">--&gt;</span></div><div class='line'><span style="color: #82AAFF;">@enddisk</span></div><div class='line'>&nbsp;</div><div class='line'><span style="color: #82AAFF;">@unlessdisk</span><span style="color: #BFC7D5;">(</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #C3E88D;">local</span><span style="color: #D9F5DD;">&#39;</span><span style="color: #BFC7D5;">)</span></div><div class='line'><span style="color: #BFC7D5;"> </span><span style="color: #697098;">&lt;!--</span><span style="color: #697098;"> The application is not using the local disk... </span><span style="color: #697098;">--&gt;</span></div><div class='line'><span style="color: #82AAFF;">@enddisk</span></div></code></pre> </div> <script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script><script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CKYILK3E&placement=laravelcom" id="_carbonads_js"></script> </div> </section> </section> </div> </section> </div> </div> <footer class="relative pt-12 dark:bg-dark-700"> <div class="max-w-screen-2xl mx-auto w-full px-8"> <div> <a href="/" class="inline-flex"> <img class="w-16 h-16" src="/img/logomark.min.svg" alt="Laravel" width="64" height="64" loading="lazy"> </a> </div> <div class="mt-6 grid grid-cols-12 md:gap-x-8 gap-y-12 sm:mt-12"> <div class="col-span-12 lg:col-span-4"> <p class="max-w-sm text-xs text-gray-700 sm:text-sm dark:text-gray-500"> Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in most web projects.</p> <ul class="mt-6 flex items-center space-x-3"> <li> <a href="https://x.com/laravelphp"> <img class="hidden dark:inline-block w-6 h-6" src="/img/social/x.dark.min.svg" alt="X" width="24" height="20" loading="lazy"> <img class="inline-block dark:hidden w-6 h-6" src="/img/social/x.min.svg" alt="X" width="24" height="20" loading="lazy"> </a> </li> <li> <a href="https://github.com/laravel"> <img class="hidden dark:inline-block w-6 h-6" src="/img/social/github.dark.min.svg" alt="GitHub" width="24" height="24" loading="lazy"> <img class="inline-block dark:hidden w-6 h-6" src="/img/social/github.min.svg" alt="GitHub" width="24" height="24" loading="lazy"> </a> </li> <li> <a href="https://discord.gg/laravel"> <img class="hidden dark:inline-block w-6 h-6" src="/img/social/discord.dark.min.svg" alt="Discord" width="21" height="24" loading="lazy"> <img class="inline-block dark:hidden w-6 h-6" src="/img/social/discord.min.svg" alt="Discord" width="21" height="24" loading="lazy"> </a> </li> <li> <a href="https://www.youtube.com/laravelphp"> <img class="hidden dark:inline-block w-6 h-6" src="/img/social/youtube.dark.min.svg" alt="YouTube" width="169" height="150" loading="lazy"> <img class="inline-block dark:hidden w-6 h-6" src="/img/social/youtube.min.svg" alt="YouTube" width="169" height="150" loading="lazy"> </a> </li> </ul> </div> <div class="text-xs col-span-6 md:col-span-3 lg:col-span-2"> <span class="uppercase dark:text-gray-200">Highlights</span> <div class="mt-5"> <ul class="space-y-3 text-gray-700 dark:text-gray-500"> <li> <a href="/docs/11.x/releases" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Release Notes</a> </li> <li> <a href="/docs/11.x/installation" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Getting Started</a> </li> <li> <a href="/docs/11.x/routing" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Routing</a> </li> <li> <a href="/docs/11.x/blade" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Blade Templates</a> </li> <li> <a href="/docs/11.x/authentication" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Authentication</a> </li> <li> <a href="/docs/11.x/authorization" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Authorization</a> </li> <li> <a href="/docs/11.x/artisan" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Artisan Console</a> </li> <li> <a href="/docs/11.x/database" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Database</a> </li> <li> <a href="/docs/11.x/eloquent" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Eloquent ORM</a> </li> <li> <a href="/docs/11.x/testing" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Testing</a> </li> </ul> </div> </div> <div class="text-xs col-span-6 md:col-span-3 lg:col-span-2"> <span class="uppercase dark:text-gray-200">Resources</span> <div class="mt-5"> <ul class="space-y-3 text-gray-700 dark:text-gray-500"> <li> <a href="https://bootcamp.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Laravel Bootcamp</a> </li> <li> <a href="https://laracasts.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Laracasts</a> </li> <li> <a href="https://laravel-news.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Laravel News</a> </li> <li> <a href="https://laracon.us" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Laracon</a> </li> <li> <a href="https://laracon.au" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Laracon AU</a> </li> <li> <a href="https://laracon.eu/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Laracon EU</a> </li> <li> <a href="https://laracon.in/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Laracon India</a> </li> <li> <a href="https://larabelles.com/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Larabelles</a> </li> <li> <a href="https://laravel.com/careers" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Careers</a> </li> <li> <a href="https://larajobs.com/?partner=5" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Jobs</a> </li> <li> <a href="https://laracasts.com/discuss" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Forums</a> </li> <li> <a href="/trademark" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Trademark</a> </li> </ul> </div> </div> <div class="text-xs col-span-6 md:col-span-3 lg:col-span-2"> <span class="uppercase dark:text-gray-200">Partners</span> <div class="mt-5"> <ul class="space-y-3 text-gray-700 dark:text-gray-500"> <li> <a href="https://vehikl.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Vehikl</a> </li> <li> <a href="https://webreinvent.com/?utm_source=laravel&amp;utm_medium=laravel.com&amp;utm_campaign=footer-link" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">WebReinvent</a> </li> <li> <a href="https://tighten.co" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Tighten</a> </li> <li> <a href="https://www.bacancytechnology.com/hire-laravel-developer?utm_source=laravel&amp;utm_medium=partners.laravel&amp;utm_campaign=sponsors" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Bacancy</a> </li> <li> <a href="https://64robots.com/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">64 Robots</a> </li> <li> <a href="https://activelogic.com/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Active Logic</a> </li> <li> <a href="https://www.blackairplane.com/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Black Airplane</a> </li> <li> <a href="https://www.byte5.net/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Byte 5</a> </li> <li> <a href="https://www.curotec.com/services/technologies/laravel/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Curotec</a> </li> <li> <a href="https://www.cyber-duck.co.uk/how-we-work/technology/laravel?utm_source=Laravel%20Partner&amp;utm_medium=Sponsorship" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Cyber-Duck</a> </li> <li> <a href="https://devsquad.com/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">DevSquad</a> </li> <li> <a href="https://jump24.co.uk/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Jump24</a> </li> <li> <a href="https://kirschbaumdevelopment.com/" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Kirschbaum</a> </li> </ul> </div> </div> <div class="text-xs col-span-6 md:col-span-3 lg:col-span-2"> <span class="uppercase dark:text-gray-200">Ecosystem</span> <div class="mt-5"> <ul class="space-y-3 text-gray-700 dark:text-gray-500"> <li> <a href="/docs/11.x/starter-kits#laravel-breeze" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Breeze</a> </li> <li> <a href="/docs/11.x/billing" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Cashier</a> </li> <li> <a href="/docs/11.x/dusk" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Dusk</a> </li> <li> <a href="/docs/11.x/broadcasting" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Echo</a> </li> <li> <a href="https://envoyer.io" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Envoyer</a> </li> <li> <a href="https://forge.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Forge</a> </li> <li> <a href="https://herd.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Herd</a> </li> <li> <a href="/docs/11.x/horizon" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Horizon</a> </li> <li> <a href="https://inertiajs.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Inertia</a> </li> <li> <a href="https://jetstream.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Jetstream</a> </li> <li> <a href="https://livewire.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Livewire</a> </li> <li> <a href="https://nova.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Nova</a> </li> <li> <a href="/docs/11.x/octane" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Octane</a> </li> <li> <a href="/docs/11.x/pennant" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Pennant</a> </li> <li> <a href="/docs/11.x/pint" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Pint</a> </li> <li> <a href="/docs/11.x/prompts" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Prompts</a> </li> <li> <a href="https://pulse.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Pulse</a> </li> <li> <a href="https://reverb.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Reverb</a> </li> <li> <a href="/docs/11.x/sail" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Sail</a> </li> <li> <a href="/docs/11.x/sanctum" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Sanctum</a> </li> <li> <a href="/docs/11.x/scout" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Scout</a> </li> <li> <a href="/docs/11.x/socialite" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Socialite</a> </li> <li> <a href="https://spark.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Spark</a> </li> <li> <a href="/docs/11.x/telescope" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Telescope</a> </li> <li> <a href="https://vapor.laravel.com" class="transition-colors hover:text-gray-600 dark:hover:text-gray-400">Vapor</a> </li> </ul> </div> </div> </div> <div class="mt-10 border-t pt-6 pb-16 border-gray-200 dark:border-dark-500"> <p class="text-xs text-gray-700 dark:text-gray-400"> Laravel is a Trademark of Laravel Holdings Inc.<br /> Copyright &copy; 2011-2024 Laravel Holdings Inc. </p> <p class="mt-6 text-xs text-gray-700 dark:text-gray-400"> Code highlighting provided by <a href="https://torchlight.dev">Torchlight</a> </p> </div> </div> </footer> <script> var algolia_app_id = 'E3MIRNPJH5'; var algolia_search_key = '1fa3a8fec06eb1858d6ca137211225c0'; var version = '11.x'; </script> <script> var _gaq=[['_setAccount','UA-23865777-1'],['_trackPageview']]; (function(d,t){ var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js'; s.parentNode.insertBefore(g,s) }(document,'script')); </script> <!-- HubSpot --> <script type="text/javascript" id="hs-script-loader" async defer src="//js-na1.hs-scripts.com/45240648.js"></script> <div class="fixed"> <input type="text"> </div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10