g3n1us/laravel-react-sync

Coordinate React frontends with a Laravel controller for updates and maintaining a universal frontend and backend application state

Installs: 248

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 1

Open Issues: 0

Language:JavaScript

Type:package

v2.0.0-beta 2019-12-21 01:39 UTC

This package is auto-updated.

Last update: 2024-04-16 09:48:26 UTC


README

68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f332f33642f4c61726176656c4c6f676f2e706e672f32313270782d4c61726176656c4c6f676f2e706e6768747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f612f61372f52656163742d69636f6e2e7376672f33323070782d52656163742d69636f6e2e7376672e706e67

Make your React components and Laravel models play nicely!

Installation

Install using Composer:

composer require g3n1us/laravel-react-sync

Note: The next step will be unnecessary in most cases

If using Laravel 5.5 or later and autodiscovery is not disabled, the package will be discovered and ready to use automatically. If NOT, then add the service provider to the list of providers in config/app.php.

'providers' => [
	/*
	 * Application Service Providers...
	 */
	 G3n1us\LaravelReactSync\LaravelReactSyncServiceProvider::class,
]

Run react-sync Preset

If this you are installing the library on a fresh Laravel installation, run the preset Artisan command to complete installation

Note: If this is NOT a fresh installation, do no run this command. Instead, you can run php artisan vendor:publish to copy the necessary files into your resources directory.

php artisan preset react-sync

Follow the onscreen instructions, and run:

npm install && npm run dev

Installation is complete!

Usage

ReactSync provides two base components to be used in the place of the standard React.Component. The first MasterComponent is hydrated with the Laravel view's data. This is set via an included Blade template in the top of your application's markup. The provides a global object that contains application data that maps to the data that is part of the context of the Blade view. Additionally, this object contains objects and methods that provide access to the underlying Laravel application's data, such as the Request, defined Guards, the Route and the authenticated user.

This data can be used in components extending this class. Changes set via a traditional web form (or form fields) will mutate your state and trigger a render as you would expect in React.

Alternately, the ReactSyncAppData.page_data object can be mutated manually to trigger a refresh, as this object is set as the components initial state.

GH Pages URL https://g3n1us.github.io/laravel-react-sync/