pkboom/laravel-inertia-vue-component

0.23 2021-04-26 16:59 UTC

This package is auto-updated.

Last update: 2022-11-26 20:26:47 UTC


README

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"