PHPackages                             zmyslny/laravel-inline-scripts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. zmyslny/laravel-inline-scripts

ActivePackage

zmyslny/laravel-inline-scripts
==============================

Converts your JavaScript code, stored in files, into a custom blade directive and inline it in HTML.

v1.2.0(1mo ago)048MITPHPPHP ^8.2CI passing

Since Oct 4Pushed 1mo agoCompare

[ Source](https://github.com/Zmyslny/laravel-inline-scripts)[ Packagist](https://packagist.org/packages/zmyslny/laravel-inline-scripts)[ RSS](/packages/zmyslny-laravel-inline-scripts/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (16)Versions (9)Used By (0)

Laravel Inline Scripts
======================

[](#laravel-inline-scripts)

 [![Build Status](https://github.com/zmyslny/laravel-inline-scripts/actions/workflows/tests.yml/badge.svg)](https://github.com/zmyslny/laravel-inline-scripts/actions) [![Latest Version](https://camo.githubusercontent.com/0dd7faa5415a65089aae4593ee4b5fd74cb9b3738d5f89f3def7550ed4b693fd/68747470733a2f2f706f7365722e707567782e6f72672f7a6d79736c6e792f6c61726176656c2d696e6c696e652d736372697074732f762f737461626c652e737667)](https://packagist.org/packages/zmyslny/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](scripts/ColorSchemeSwitchTwoStates/README.md) - light / dark - color scheme switching script *(+ view with icons)*
- [ColorSchemeSwitchTwoStates](scripts/ColorSchemeSwitchThreeStates/README.md) - light / dark / system - color scheme switching script *(+ view with icons)*
- [LivewireNavAdapter](scripts/LivewireNavAdapter/README.md) - color scheme navigation state adapter for Livewire

### Requirements

[](#requirements)

- PHP 8.2 or newer
- Laravel 9.x or newer (wasn't tested with the older versions)

🚀 Quick Start
-------------

[](#-quick-start)

Install the package via Composer:

```
composer require zmyslny/laravel-inline-scripts
```

Register a custom Blade directive for your JavaScript in your `AppServiceProvider`:

```
class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        BladeInlineScripts::takeFiles(
            resource_path('js/your-first-script.js'),
            resource_path('js/your-second-script.js'),
            ...
        )->registerAs('myInlineScripts');
    }
}
```

Use the custom Blade directive in your template to inline the scripts:

```

    ...

    @myInlineScripts

    ...
```

Done.

Using Built-in Scripts
----------------------

[](#using-built-in-scripts)

The package includes ready-to-use scripts. For example, to add a color scheme switcher:

```
use Zmyslny\LaravelInlineScripts\Ready\ColorSchemeSwitchTwoStates\InitScript;
use Zmyslny\LaravelInlineScripts\Ready\ColorSchemeSwitchTwoStates\SwitchScript;

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        BladeInlineScripts::take(
            new InitScript(),
            new SwitchScript('d') // toggle dark & light modes with 'd' key
        )->registerAs('colorScheme');
    }
}
```

Then use in your template:

```
@colorScheme
```

See the [Color Scheme Switch](scripts/ColorSchemeSwitchTwoStates/README.md), [Color Scheme Three States](scripts/ColorSchemeSwitchThreeStates/README.md), and [LivewireNavAdapter](scripts/LivewireNavAdapter/README.md) documentation for full details and customization options.

Advanced Usage
--------------

[](#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](scripts/ColorSchemeSwitchTwoStates/README.md) documentation.

License
-------

[](#license)

This package is licensed under the MIT License.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance90

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~23 days

Recently: every ~41 days

Total

8

Last Release

55d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eac6eafbce6bffead405e76b63af169e2d51bf18f75bdfe8c057e2b0f2ecf36e?d=identicon)[zmyslny](/maintainers/zmyslny)

---

Top Contributors

[![Zmyslny](https://avatars.githubusercontent.com/u/28888253?v=4)](https://github.com/Zmyslny "Zmyslny (178 commits)")

---

Tags

inline-scriptlaravelphp

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/zmyslny-laravel-inline-scripts/health.svg)

```
[![Health](https://phpackages.com/badges/zmyslny-laravel-inline-scripts/health.svg)](https://phpackages.com/packages/zmyslny-laravel-inline-scripts)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
