vform
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

vform

Handle Laravel-Vue forms and validation with ease

Latest Version on NPM Build Status Total Downloads

vform is a tiny library for Vue 2/3 to help with forms and validation when using Laravel as a back-end.

It provides a form instance to wrap your data in a convenient way and send it to your Laravel application via an HTTP request using axios.

Installation

npm install axios vform

Basic Usage

<template>
  <form @submit.prevent="login" @keydown="form.onKeydown($event)">
    <input v-model="form.username" type="text" name="username" placeholder="Username">
    <div v-if="form.errors.has('username')" v-html="form.errors.get('username')" />

    <input v-model="form.password" type="password" name="password" placeholder="Password">
    <div v-if="form.errors.has('password')" v-html="form.errors.get('password')" />

    <button type="submit" :disabled="form.busy">
      Log In
    </button>
  </form>
</template>

<script>
import Form from 'vform'

export default {
  data: () => ({
    form: new Form({
      username: '',
      password: ''
    })
  }),

  methods: {
    async login () {
      const response = await this.form.post('/api/login')
      // ...
    }
  }
}
</script>

Laravel Controller:

<?php

class LoginController extends Controller
{
    public function login(Request $request)
    {
        $this->validate($request, [
            'username' => 'required',
            'password' => 'required',
        ]);

        // ...
    }
}

Documentation

You'll find the documentation on vform.vercel.app.

Changelog

Please see CHANGELOG for more information what has changed recently.

Package Sidebar

Install

npm i vform

Weekly Downloads

3,242

Version

2.1.2

License

MIT

Unpacked Size

46.4 kB

Total Files

37

Last publish

Collaborators

  • cretueusebiu