A Laravel Blade directive to export PHP variables to JavaScript with a simple @javascript syntax.
Spatie Laravel Blade JavaScript is a Laravel package that adds a Blade directive to export PHP variables to JavaScript. It allows developers to seamlessly pass server-side data to client-side scripts using a simple `@javascript` syntax in Blade templates, eliminating the need for manual script tag creation and JSON encoding.
Laravel developers building applications that require passing server-side data to JavaScript, particularly those using Blade templates and wanting a clean, integrated solution.
It provides a minimal, elegant syntax for a common task, reducing boilerplate code and potential errors. The package is lightweight, automatically registered, and configurable, making it a convenient alternative to manual implementations or heavier solutions.
A Blade directive to export variables to JavaScript
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The @javascript directive simplifies variable passing with minimal code, eliminating the need for manual JSON encoding and script tag creation, as shown in the README examples.
Allows variables to be scoped under a custom namespace to avoid global pollution, easily set via a config file, providing flexibility for organized codebases.
Users can publish and edit the Blade view to modify the script tag, such as adding type attributes or CSP nonces, offering control over security and compliance.
Automatically registers upon Composer installation, requiring no additional setup for basic usage, making it quick to integrate into Laravel projects.
Confined to Blade templates, so it cannot be used in other Laravel contexts like APIs or console commands without workarounds, limiting its versatility.
Handles simple values well but may not efficiently manage complex nested objects or large datasets, as it outputs raw JavaScript assignments without optimization.
Lacks built-in security features like automatic nonce generation; users must manually publish views to comply with strict CSP policies, adding maintenance burden.