Skip to content

My goal in creating this package was to enable Laravel developers to quickly generate Livewire components for CRUD functionality on a specific model, all with a single PHP Artisan command.

License

Notifications You must be signed in to change notification settings

MedRachy/CrudLivewire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CrudLivewire

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

About

My goal in creating this package was to enable Laravel developers to quickly generate Livewire components for CRUD functionality on a specific model, all with a single PHP Artisan command.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages