Vueloquent brings Laravel's query builder to the front-end as a Vue plugin or plain JavaScript module, providing the same convenient, fluent interface for creating and running database queries all while using a single route to handle queries for all models.
Vue.eloquent.token('api_token').at('endpoint').from('User').find(1);
or
$v
.token('api_token')
.at('endpoint')
.from('User')
.with('posts')
.where('published', true)
.get();
- PHP 7.1+
- Laravel 5.6+
- Install the package by running this command in your terminal/cmd:
composer require charlgottschalk/vueloquent
- Publish the Vueloquent plugin
php artisan vendor:publish --tag=vueloquent-vue
Include the self-installing plugin after Vue.
<script src="/js/app.js"></script>
<script src="/js/vendor/vueloquent/vueloquent.plugin.js"></script>
Once loaded, you will be able to access Vueloquent globally in your Vue instances at Vue.eloquent
.
php artisan vendor:publish --tag=vueloquent-js
Include the script before your closing </body>
tag.
<script src="/js/vendor/vueloquent/vueloquent.plain.js"></script>
Once loaded, you will be able to access Vueloquent at $v
.
You will need to create a post
route that will handle all Vueloquent queries. I suggest creating an api route in your routes\api.php
file.
use Illuminate\Http\Request;
use CharlGottschalk\Vueloquent\VueloquentHandler;
Route::middleware('auth:api')->post('[vueloquent_route]', function (Request $request, VueloquentHandler $handler) {
return $handler->handle($request);
});
Replace [vueloquent_route]
with the endpoint you wish.
For more in-depth documentation, please visit the wiki.
- Query Denials
- Authorization Handling
This project is licensed under the MIT License - see the LICENSE file for details