exolnet / laravel-vue-data
Adds utilities to easily pass data from Laravel to Vue.
Installs: 6 695
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- exolnet/phpcs-config: ^2.0
- laravel/pint: ^1.2
- mockery/mockery: ^1.4
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.6
README
Adds utilities to easily pass data from Laravel to Vue.
Installation
Require this package with composer:
composer require exolnet/laravel-vue-data
If you don't use package auto-discovery, add the service provider to the providers
array in config/app.php
:
Exolnet\VueData\VueDataServiceProvider::class
And the facade to the facades
array in config/app.php
:
'Vue' => Exolnet\VueData\Facades\Vue::class
Usage
Define variables
First, you need to devine variable that will be available in your Vue application.
In your PHP code:
Vue::put('variable', 'value')
In a Blade view:
@vue('variable', 'value')
Make variables available
In your base layout, add the following view before your main app.js
to make the variables available:
@include('vue-data::variables')
Use variables
In your app.js
, use the variables defined when they are available:
new Vue({ el: '#app', data: () => window.App || {}, });
Testing
To run the phpUnit tests, please use:
composer test
Contributing
Please see CONTRIBUTING and CODE OF CONDUCT for details.
Security
If you discover any security related issues, please email security@exolnet.com instead of using the issue tracker.
Credits
License
This code is licensed under the MIT license. Please see the license file for more information.