Download the PHP package zmyslny/laravel-inline-scripts without Composer
On this page you can find all versions of the php package zmyslny/laravel-inline-scripts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zmyslny/laravel-inline-scripts
More information about zmyslny/laravel-inline-scripts
Files in zmyslny/laravel-inline-scripts
Package laravel-inline-scripts
Short Description Converts your JavaScript code, stored in files, into a custom blade directive and inline it in HTML.
License MIT
Informations about the package laravel-inline-scripts
Laravel Inline Scripts
A Laravel package that provides a simple way to wrap JavaScript code stored in a file into a PHP class and inline it using a custom Blade directive. The PHP wrapper class also allows you to modify the script before inlining (for example, by replacing placeholders).
Allows ✨:
- passing variables from PHP to JavaScript,
- process / modify the script in a dedicated PHP class.
Additionally - has build in ready-to-use scripts (built using this package):
- ColorSchemeSwitchThreeStates - light / dark - color scheme switching script (+ view with icons)
- ColorSchemeSwitchTwoStates - light / dark / system - color scheme switching script (+ view with icons)
- LivewireNavAdapter - color scheme navigation state adapter for Livewire
Requirements
- PHP 8.2 or newer
- Laravel 9.x or newer (wasn't tested with the older versions)
🚀 Quick Start
Install the package via Composer:
Register a custom Blade directive for your JavaScript in your AppServiceProvider:
Use the custom Blade directive in your template to inline the scripts:
Done.
Using Built-in Scripts
The package includes ready-to-use scripts. For example, to add a color scheme switcher:
Then use in your template:
See the LivewireNavAdapter documentation for full details and customization options.
Advanced Usage
For more advanced script processing, create a PHP class that implements the RenderableScript interface to prepare or transform your JavaScript code. Use the abstract class FromFile to load scripts from files, or FromFileWithPlaceholders to include placeholder replacement (e.g., __VARIABLE__ → value).
Register your custom scripts using BladeInlineScripts::take(...).
For a complete working example with detailed setup instructions, see the Color Scheme Switch documentation.
License
This package is licensed under the MIT License.