Looking to hire Laravel developers? Try LaraJobs

laravel-inertia-vue-component maintained by pkboom

Author
Last update
2021/04/26 18:59 (dev-master)
License
Downloads
18

Comments
comments powered by Disqus

Opinionated Inertia Vue Component Creator

Installation

Install the package via composer:

composer require pkboom/laravel-inertia-vue-component

Usage

Create a new controller, which contains Inertia:render.

// SomeController.php

public function index() {
    return Inertia::render('Some/Index', [
        'foo' => 'foo',
        'bar' => 'bar',
    ]);
}

Run this command.

php artisan make:inertia-vue-component <Controller Name>
// e.g. php artisan make:inertia-vue-component SomeController

js/Pages/Some/Index.vue is created with props

export default {
    props: {
        foo: String,
        bar: String,
    }
    ...
}

To add a prop to an existing component, first add a new key => value to Inertia::render.

// SomeController.php

public function index() {
    return Inertia::render('Some/Index', [
        'foo' => 'foo',
        'bar' => 'bar',
        'new' => 'new',
    ]);
}

Run this command.

php artisan make:inertia-vue-component SomeController

A new prop is created in js/Pages/Some/Index.vue.

export default {
    props: {
        new: String,
        foo: String,
        bar: String,
    }
    ...
}

Publish to edit stub.

php artisan vendor:publish --provider="Pkboom\InertiaVueComponent\InertiaVueComponentServiceProvider"