Download the PHP package mustafarefaey/laravel-hybrid-spa without Composer
On this page you can find all versions of the php package mustafarefaey/laravel-hybrid-spa. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mustafarefaey/laravel-hybrid-spa
More information about mustafarefaey/laravel-hybrid-spa
Files in mustafarefaey/laravel-hybrid-spa
Package laravel-hybrid-spa
Short Description Laravel hybrid SPA response helpers.
License MIT
Homepage https://github.com/mustafarefaey/laravel-hybrid-spa
Informations about the package laravel-hybrid-spa
Laravel hybrid SPA response helpers.
Laravel HTTP Response classes, to help you build a hybrid SPA!
Contents table
-
Installation
-
ApiResponse
- Success response
- Success response optional parameters
- Success response format
- Fail response
- Fail response optional parameters
- Fail response format
- Success response
- HybridResponse
- HTML response content
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
artesaos/seotools
package is used to set meta tags. Please check their configuration documentation.
ApiResponse
Use this class in your controllers' actions to return a consistent JSON response.
Success response
Use success
method When returning a successful response.
Success response optional parameters
data
: an array of any data, this will be json encoded.
messages
: an array of any messages, this will be json encoded.
HTTP status code
: by default this will be 200, unless you specify it.
Success response format
Fail response
Use fail
method When returning a failure response.
Fail response optional parameters
data
: an array of any data, this will be json encoded.
messages
: an array of any messages, this will be json encoded.
HTTP status code
: by default this will be 400, unless you specify it.
Fail response format
HybridResponse
Use this class in your controllers' actions to return an html page that loads the js app, passing it the initial page state.
If the request expects JSON response, it will return the page's state in an ApiResponse
.
HTML response content
-
Inside head tag:
-
Usually needed meta tags:
- Favicons: you can set them in the config file.
- SEO meta tags: This package uses
artesaos/seotools
package to set meta tags. Please review their documentation.
-
- Inside body tag:
- Div element that will mount the JS app: you can set its ID in the config file.
- 5 global JS variables:
window.__SHARED_STATE__
: This is where the shared state is injected.- You can rename this variable in the config file.
- To control its value, You can create a class that extends the
MustafaRefaey\LaravelHybridSpa\RetrievesSharedState
interface, then updateshared-state-handler
in the config file, accordingly.
window.__PAGE_STATE__
: This is where the page state is injected.- You can rename this variable in the config file.
window.__SKIP_LOADING_PAGE_STATE_ONCE__
: This variable is used to help the JS app to skip calling the backe-end for the page state, and usingwindow.__PAGE_STATE__
directly. Its initial value istrue
, and you should set it tofalse
once you usedwindow.__PAGE_STATE__
.window.__SESSION_SUCCESS_MESSAGES__
: This is where the session success messages are injected.window.__SESSION_ERROR_MESSAGES__
: This is where the session error messages are injected.
- The JS app script: you can set its URL in the config file.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
This package uses the package artesaos/seotools to set meta tags.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-hybrid-spa with dependencies
artesaos/seotools Version ^0.19.1
illuminate/contracts Version ^6.0|^7.0|^8.0