Posts Learn Snippets Categories Tags About

How to Push Stacks Only Once in Laravel

Learn how to push your styling or scripts inside stacks once only to prevent code duplication

Created on Jul 03, 2021


If you face an issue where you are pushing multiple styling or scripts in a single blade file, you can prevent this by wrapping the "stack" with the "once" directive.

The "once" directive will only evaluate the stacks once per rendering cycle which will ensure that there won't be code duplicate.

Laravel Once Directive
For javascript/js stacks you can define it like this.
            console.log('hello world');

For styles/CSS stacks it's pretty much the same.
            .card { background-color: pink; }

Created by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.