Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Make Crud Laravel Package

lanciweb/laravel-make-crud

Laravel package that scaffolds full CRUD for a model via php artisan make:crud. Generates model, resource controller, migration, seeder, routes, and Blade views by default; supports Admin prefixes, API mode, and pick-and-choose options (controller, factory, policy, requests, views, etc.).

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation: Run composer require lanciweb/laravel-make-crud in your Laravel project.
  2. First Command: Execute php artisan make:crud Post to generate a full CRUD scaffold for a Post model.
  3. Verify Output:
    • Check app/Models/Post.php (model).
    • Check app/Http/Controllers/PostController.php (controller).
    • Check database/migrations/ for the migration file.
    • Check routes/web.php for registered routes.
    • Check resources/views/posts/ for Blade templates.

First Use Case

Generate a basic blog post CRUD:

php artisan make:crud BlogPost
  • Run the migration: php artisan migrate.
  • Visit /blog-posts in your browser to see the auto-generated index page.

Implementation Patterns

Core Workflows

  1. Standard CRUD Generation Use php artisan make:crud ModelName for a full-stack CRUD with:

    • Model, migration, controller, views, and routes.
    • Example: php artisan make:crud User.
  2. API-Only CRUD Use --api for API-focused CRUD (controller in app/Http/Controllers/Api/):

    php artisan make:crud Product --api
    
    • Generates JSON responses (no Blade views).
    • Registers routes in routes/api.php.
  3. Namespaced/Grouped CRUD Use prefixes (e.g., Admin/Post) to organize resources:

    php artisan make:crud Admin/Post
    
    • Routes prefixed with admin/ (e.g., /admin/posts).
    • Views in resources/views/admin/posts/.
    • Controller in app/Http/Controllers/Admin/PostController.php.
  4. Customizing Fields Override default fields by editing the generated migration or model. Example: Add a published_at column to the migration:

    $table->timestamp('published_at')->nullable();
    
  5. Extending Views Modify Blade templates in resources/views/{prefix}/{model}/ to customize UI. Example: Edit edit.blade.php to add custom form fields.

  6. Seeding Data Use the auto-generated seeder (database/seeders/PostSeeder.php) to populate test data:

    php artisan db:seed --class=PostSeeder
    

Integration Tips

  • Validation: Extend the controller’s rules() method to add custom validation:
    public function rules()
    {
        return [
            'title' => 'required|max:255',
            'content' => 'required',
            // Custom rule
            'slug' => 'required|unique:posts',
        ];
    }
    
  • Authorization: Use Laravel’s gates/policies in the controller’s constructor:
    public function __construct()
    {
        $this->middleware('auth');
        $this->authorizeResource(Post::class);
    }
    
  • Relationships: Define relationships in the model (e.g., belongsToMany) and update the migration/controller to handle them.
  • Form Requests: Replace the controller’s validate() with a custom FormRequest for complex validation:
    php artisan make:request StorePostRequest
    
    Then update the controller to use it:
    public function store(StorePostRequest $request)
    

Gotchas and Tips

Pitfalls

  1. Route Conflicts

    • Prefixes (e.g., Admin/Post) may conflict with existing routes. Check routes/web.php for duplicates.
    • Fix: Manually adjust route names or prefixes.
  2. View Overwrites

    • Regenerating a CRUD will overwrite existing views. Backup or exclude views if customizing:
      # Skip views (generates only model, controller, migration)
      php artisan make:crud Post --skip-views
      
  3. Migration Timestamps

    • The package adds created_at/updated_at by default. Disable in the migration if using soft deletes or custom timestamps:
      $table->softDeletes(); // Requires 'use SoftDeletes;'
      $table->timestamps(false); // Disable auto-timestamps
      
  4. API vs. Web Routes

    • --api generates routes in routes/api.php, but the controller may still use web middleware. Explicitly set middleware in the constructor:
      public function __construct()
      {
          $this->middleware('api'); // For API controllers
      }
      
  5. Seeder Conflicts

    • Running php artisan db:seed may duplicate data if the seeder runs multiple times. Use if (App::runningInConsole()) checks or Laravel’s ShouldBeSeeded trait.
  6. Namespace Mismatches

    • If the model namespace doesn’t match the controller’s use statement, the controller will fail. Verify namespaces in both files.

Debugging

  • Missing Routes: Clear cached routes:
    php artisan route:clear
    
  • Controller Not Found: Ensure the controller’s namespace matches the route definition (e.g., Admin\PostController for admin.posts).
  • View Errors: Check for typos in Blade template paths (e.g., resources/views/posts/index.blade.php).
  • Migration Errors: Run php artisan migrate:status to debug failed migrations.

Configuration Quirks

  1. Custom Blade Directives The package uses basic Blade directives. Extend them in app/Providers/AppServiceProvider:

    Blade::directive('custom', function ($expression) {
        return "<?php echo $expression; ?>";
    });
    
  2. Resource Controller Overrides The generated controller extends App\Http\Controllers\Controller. Override methods like index(), store(), etc., but preserve the @method annotations for API documentation.

  3. Form Helper Usage The views use Laravel Collective’s Form and Html helpers. Install them if missing:

    composer require laravelcollective/html
    

    Add to config/app.php:

    'providers' => [
        Collective\Html\HtmlServiceProvider::class,
        Collective\Form\FormServiceProvider::class,
    ],
    'aliases' => [
        'Form' => Collective\Html\FormFacade::class,
        'Html' => Collective\Html\HtmlFacade::class,
    ],
    

Extension Points

  1. Custom Templates Override the package’s Blade templates by publishing them:

    php artisan vendor:publish --tag=make-crud-views
    

    Then modify files in resources/views/vendor/make-crud/.

  2. Dynamic Field Generation Extend the package’s logic by creating a custom command. Copy the package’s MakeCrudCommand and modify it in app/Console/Commands/MakeCustomCrud.php.

  3. Additional Files The package skips generating tests, factories, or observers. Add them manually or extend the command to include them:

    php artisan make:model Post --factory --migration --controller --resource
    
  4. Localization The views use static text. For localization, wrap strings in __() and publish the language files:

    php artisan vendor:publish --tag=laravel-translations
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours