How to Use the Laravel CRUD Generator

Sep 18, 2021 | Programming

In the world of Laravel development, creating a CRUD (Create, Read, Update, Delete) application can often be time-consuming. Fortunately, with the Laravel CRUD Generator v2.x, this process is simplified to just a single command. Whether you are using Bootstrap, Tailwind CSS, or Livewire, this powerful package will help you create a comprehensive foundation for your Laravel applications quickly and efficiently.

Requirements

  • Laravel: 10.x
  • PHP: 8.1

Installation

Before you dive into generating your CRUD resources, you need to install the package:

  • Run the following command in your terminal:
  • composer require ibex/crud-generator --dev
  • Optionally, you can publish the default package configuration by running:
  • php artisan vendor:publish --tag=crud
  • For older Laravel versions (10.x), please use version 1.x with:
  • composer require ibex/crud-generator:1.6 --dev

Usage

Now that you have installed the package, it’s time to use it! Follow these steps:

  • To generate the necessary CRUD components, execute the command:
  • php artisan make:crud table_name
  • For example, to create a CRUD for a bank:
  • php artisan make:crud banks
  • Add a route in your web.php:
  • Route::resource('banks', BankController::class);
  • For Livewire components, add the following routes:
  • 
    Route::get('banks', App\Livewire\BanksIndex::class)->name('banks.index');
    Route::get('banks/create', App\Livewire\BanksCreate::class)->name('banks.create');
    Route::get('banks/{bank}', App\Livewire\BanksShow::class)->name('banks.show');
    Route::get('banks/{bank}/edit', App\Livewire\BanksEdit::class)->name('banks.edit');
    
  • To create API routes, add:
  • Route::apiResource('banks', BankController::class);

Options

The CRUD generator provides customizable options tailored to your needs:

  • To specify the tech stack, use:
  • php artisan make:crud table_name bootstrap
  • For Tailwind CSS:
  • php artisan make:crud banks tailwind
  • For Livewire components:
  • php artisan make:crud banks livewire
  • To create API-only controllers:
  • php artisan make:crud banks api

Personalization

The generated views can be fully customized:

  • Run the command:
  • php artisan vendor:publish --tag=crud
  • This action generates a crud.php file in your config folder.
  • You can now update the stub_path variable to define your own stub folder.
  • Copy your stub files from the package, make your alterations, and run the generation command again to see the updates in action.

Troubleshooting

If you encounter any issues while using the Laravel CRUD Generator, consider the following troubleshooting tips:

  • Ensure you are using Laravel 10.x and PHP 8.1, as these are the package requirements.
  • If the commands do not execute properly, verify your terminal permissions and environment settings.
  • Make sure you are in the correct directory of your Laravel project when running commands.
  • For any persistent issues, check the official documentation or seek support from the community.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox