medrachy/crud-livewire

Generate the CRUD livewire component for a model

dev-master 2022-09-23 15:05 UTC

This package is auto-updated.

Last update: 2025-06-23 21:41:32 UTC


README

Generate the livewire class and view for a model using the fillable attributes or the database columns, by running one command and providing the table name as argument this package generate the files (class/view) with all CRUD functions

MIT License

Features

  • Use the model instance as public variable
  • Use Jetstream components
  • Create , Update and Delete using modals
  • Manage inputs and types directly from the livewire class
  • Paginations

Requirements

  • Laravel 8+
  • Jetstream with livewire stack

Installation

You can install the package via Composer

 composer require medrachy/crud-livewire

Usage

After installation, run this command

 php artisan crud:build {tableName}   //example : users

This command will perfom below actions :

  • generate the proper (className, modelName and viewName) from the tableName
  • create livewire directory if it doesn't exist "/app/Http/Livewire"
  • generate the livewire class "/app/Http/Livewire/{className}.php"
  • create livewire directory if it doesn't exist "/resources/views/livewire"
  • generate the livewire view "/resources/views/livewire/{viewName}.blade.php"

Next open the livewire class generated "/app/Http/Livewire/{className}.php" and add the proper properties for $rules and $inputTypes

// Add the input type for each attribute
public array $inputTypes = [
        // 'attribute' => 'inputType',
        // example :
        'name' => 'text',
        'email' => 'email',
];

// Add rules
protected $rules = [
    //  'modalName.attribute' => 'required',
    // example :
    'user.name' => 'required',
    'user.email' => 'required|email',
];

And thats it, now you can render you livewire component like so :

<div>@livewire('{viewName}') // example @livewire('user-crud)</div>

Jetstream

This package use Jetstream modal component, if you dont use Jetstream in your application you need to edit the view generated by this package.

License

The MIT License (MIT). Please see License File for more information