charlgottschalk/vueloquent

Vueloquent brings Laravel's DB queries to the front-end.

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 21

Language:JavaScript


README

Latest Stable Version Total Downloads License

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.

Example:

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();

Requirements

  • PHP 7.1+
  • Laravel 5.6+

Installation

  1. Install the package by running this command in your terminal/cmd:
composer require charlgottschalk/vueloquent
  1. Publish the Vueloquent plugin

If you're using Vue

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.

If you're using plain JavaScript

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.

Route Setup

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.

Documentation

For more in-depth documentation, please visit the wiki.

To Do:

  • Query Denials
  • Authorization Handling

License

This project is licensed under the MIT License - see the LICENSE file for details