PHPackages                             estey/laravel-react-middleware - 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. [Framework](/categories/framework)
4. /
5. estey/laravel-react-middleware

ActiveLibrary[Framework](/categories/framework)

estey/laravel-react-middleware
==============================

Middleware for React.js server-side rendering in Laravel.

v1.2.1(9y ago)623[1 issues](https://github.com/BradEstey/laravel-react-middleware/issues)MITPHPPHP &gt;=5.5.9

Since Apr 15Pushed 9y ago2 watchersCompare

[ Source](https://github.com/BradEstey/laravel-react-middleware)[ Packagist](https://packagist.org/packages/estey/laravel-react-middleware)[ Docs](http://www.bradestey.com/projects/laravel-react-middleware)[ RSS](/packages/estey-laravel-react-middleware/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (7)Versions (12)Used By (0)

Laravel React Compiler Middleware
=================================

[](#laravel-react-compiler-middleware)

[![Latest Stable Version](https://camo.githubusercontent.com/b93a61205c1bcfb87737df88d7783227a652c553a6477122f01c04d7df5acf0a/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65737465792f6c61726176656c2d72656163742d6d6964646c65776172652e737667)](https://packagist.org/packages/estey/laravel-react-middleware) [![Build Status](https://camo.githubusercontent.com/409cf4c1d482818321b25f20b60325e6443bd03021e4bc6d2bbbc924798fcc2e/68747470733a2f2f7472617669732d63692e6f72672f4272616445737465792f6c61726176656c2d72656163742d6d6964646c65776172652e737667)](https://travis-ci.org/BradEstey/laravel-react-middleware) [![Coverage Status](https://camo.githubusercontent.com/4464105d51b160fd808e083cc8f516ce3c9a5be095b0ca82266ff18bbf84cabb/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4272616445737465792f6c61726176656c2d72656163742d6d6964646c65776172652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/BradEstey/laravel-react-middleware?branch=master)

This is a [Laravel](https://laravel.com) middleware used to help with [React Server-side Rendering](https://facebook.github.io/react/docs/environments.html#node). This middleware makes an HTTP request to a local [Node.js](https://nodejs.org) server compiling the React application. It then injects the returned HTML into your Laravel view. Use [Blade Templates](https://laravel.com/docs/5.2/blade) as you would normally.

- [How it Works](#how-it-works)
- [Installation](#installation)
- [Configuration](#configuration)
- [Merge JSON Response](#merge-json-response)

How it Works
------------

[](#how-it-works)

First install Node.js on your production server or on a server on the same local network. Then write a small Node.js application to render your React application. For simple applications, you can use `ReactDOM.server.renderToString(App)`, for more complex React applications you may need to do something more like [this](https://github.com/reactjs/react-router/blob/master/docs/guides/ServerRendering.md).

On the Laravel side, build a Blade or plain PHP layout file as usual.

```

        {{ $title or 'Untitled Document' }}

            {!! $content or '' !!}

```

Render your views in your controller method as usual.

```
return view('layouts.main', ['title' => 'Your title here.']);
```

Add this middleware to whichever routes contain a React app.

```
Route::get('/', ['middleware' => 'react', 'uses' => 'HomeController@index']);
```

From there, the React middleware will make a request to your Node.js compiler server and replace in the `$content` variable with the returned HTML.

Installation
------------

[](#installation)

Install this package via [Composer](https://getcomposer.org).

```
$ composer require estey/laravel-react-middleware
```

Add the service provider to your `config/app.php` file.

```
'providers' => [
    ...
    Estey\ReactMiddleware\ReactCompilerServiceProvider::class,
];
```

Add the middleware class to your `app/Http/Kernel.php` file.

```
protected $routeMiddleware = [
    ...
    'react' => \Estey\ReactMiddleware\CompileReact::class,
];
```

Configuration
-------------

[](#configuration)

To publish the configuration file, run:

```
$ php artisan vendor:publish --provider="Estey\ReactMiddleware\ReactCompilerServiceProvider"
```

In the config file you can change the host and port of the compiler server and change the connection and response timeout times. The default behavior is for timeouts set be to `0`, which wait indefinitely. I highly recommend that you change these to be more aggressive.

---

AJAX requests to this route will return the data array passed to your view as plain JSON. So the example above would return:

```
{ "title": "Your title here." }
```

To disable the JSON response on AJAX requests, pass "disable\_json" to the first parameter.

```
Route::get('/', ['middleware' => 'react:disable_json', 'uses' => 'HomeController@index']);
```

Merge JSON Response
-------------------

[](#merge-json-response)

If your Node.js application responds with JSON instead of a plain HTML string, then the JSON will be parsed and merged into your view. So for example, if your Node.js application responds with:

```
{
  "content": "Hello World",
  "metaKeywords": "foo, bar, baz"
}
```

Then, both the `$content` variable and the `$metaKeywords` variable will be accessible in your view file.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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 ~16 days

Total

11

Last Release

3522d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/65050e2971f866e7a534a49d752b1d885db693dbd86f2c2ec4ab164d0b5f5723?d=identicon)[Brad Estey](/maintainers/Brad%20Estey)

---

Top Contributors

[![BradEstey](https://avatars.githubusercontent.com/u/578665?v=4)](https://github.com/BradEstey "BradEstey (22 commits)")

---

Tags

laravellaravel-middlewarereactmiddlewarelaravelreactreactjsserver-side-rendering

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/estey-laravel-react-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/estey-laravel-react-middleware/health.svg)](https://phpackages.com/packages/estey-laravel-react-middleware)
```

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

26.2k161.6k7](/packages/bagisto-bagisto)[krayin/laravel-crm

Krayin CRM

22.0k32.8k1](/packages/krayin-laravel-crm)[unopim/unopim

UnoPim Laravel PIM

9.4k1.8k](/packages/unopim-unopim)

PHPackages © 2026

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