Skip to content

Installation ​

Installing the package in your Vue 3 app.

sh
yarn add @konnec/vue-eloquent

The package is written in TypeScript and ships its own types. It requires Vue 3. axios, @vuelidate/core, @vuelidate/validators and laravel-echo are installed as dependencies.

Setup ​

Configure the package once, before your first request (e.g. in your main.ts or a boot file):

ts
import { createHttp, createBroadcast, VueEloquentPlugin } from '@konnec/vue-eloquent'

// Required: the HTTP client used by every Api, Model and Collection class.
// See the "API Class" page for all the options.
createHttp({
  baseURL: 'http://localhost:8000',
  apiPrefix: 'api' // default
})

// Optional: needed only if you broadcast events to your Collections.
// See the "Collection" page.
createBroadcast(echo)

// Optional: Vue DevTools support. Only active when NODE_ENV is not `production`.
app.use(VueEloquentPlugin)

WARNING

createHttp must be called before any Api, Model or Collection class makes a request.

What's included ​

ClassPurpose
ApiStatic methods that map to a Laravel REST resource
ModelA single record: reactive attributes, validation, state, save/find/delete
CollectionA list of records, with query building and broadcasting
AuthLaravel Sanctum login, logout and password reset
PolicyCRUD permissions and the current action mode

Laravel Package ​

This package pairs with composer's konnec/vue-eloquent-api package laravel installation.