Laravel Blade Once Component

Laravel Blade Once Component

As of Laravel 7.25, Blade now includes a new @once component that will only render the items within the tags one time. It’s a little hard to explain and much easier to show with an example, and here is one Taylor included in the original pull request:

Component content here...

        This will only be included in the template once even if component is rendered multiple times.

Then Mohamed Said followed up with another example:

<template id="recieptsTemplate">
    <div class="flex flex-column items-center">
        <div class="w-1/2" data-reciept="paid_at"></div>
        <div class="w-1/4" data-reciept="amount"></div>

<div data-id="receipts" class="divide-y divide-grey-300"></div>

This component renders a list of receipts. The template for the receipt has to be rendered once in the entire page while the component itself can be used multiple times.

This once feature is now pulled into Laravel starting with v7.25 so you can start using it today.

Filed in: News / Blade


Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Software Developer
Remote (US & Canada)
😎 Laravel Developer
Jogg, Inc
Junior, Mid, and Senior Software Engineers. Laravel / Vue. Saint Petersburg, FL
Saint Petersburg, FL and Remote
Senior PHP Developer (Laravel)
The Interaction Design Foundation
Fullstack Laravel Engineer (Munich/Remote) 💻
Munich, Germany or Remote