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.).
composer require lanciweb/laravel-make-crud in your Laravel project.php artisan make:crud Post to generate a full CRUD scaffold for a Post model.app/Models/Post.php (model).app/Http/Controllers/PostController.php (controller).database/migrations/ for the migration file.routes/web.php for registered routes.resources/views/posts/ for Blade templates.Generate a basic blog post CRUD:
php artisan make:crud BlogPost
php artisan migrate./blog-posts in your browser to see the auto-generated index page.Standard CRUD Generation
Use php artisan make:crud ModelName for a full-stack CRUD with:
php artisan make:crud User.API-Only CRUD
Use --api for API-focused CRUD (controller in app/Http/Controllers/Api/):
php artisan make:crud Product --api
routes/api.php.Namespaced/Grouped CRUD
Use prefixes (e.g., Admin/Post) to organize resources:
php artisan make:crud Admin/Post
admin/ (e.g., /admin/posts).resources/views/admin/posts/.app/Http/Controllers/Admin/PostController.php.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();
Extending Views
Modify Blade templates in resources/views/{prefix}/{model}/ to customize UI.
Example: Edit edit.blade.php to add custom form fields.
Seeding Data
Use the auto-generated seeder (database/seeders/PostSeeder.php) to populate test data:
php artisan db:seed --class=PostSeeder
rules() method to add custom validation:
public function rules()
{
return [
'title' => 'required|max:255',
'content' => 'required',
// Custom rule
'slug' => 'required|unique:posts',
];
}
public function __construct()
{
$this->middleware('auth');
$this->authorizeResource(Post::class);
}
belongsToMany) and update the migration/controller to handle them.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)
Route Conflicts
Admin/Post) may conflict with existing routes. Check routes/web.php for duplicates.View Overwrites
# Skip views (generates only model, controller, migration)
php artisan make:crud Post --skip-views
Migration Timestamps
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
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
}
Seeder Conflicts
php artisan db:seed may duplicate data if the seeder runs multiple times. Use if (App::runningInConsole()) checks or Laravel’s ShouldBeSeeded trait.Namespace Mismatches
use statement, the controller will fail. Verify namespaces in both files.php artisan route:clear
Admin\PostController for admin.posts).resources/views/posts/index.blade.php).php artisan migrate:status to debug failed migrations.Custom Blade Directives
The package uses basic Blade directives. Extend them in app/Providers/AppServiceProvider:
Blade::directive('custom', function ($expression) {
return "<?php echo $expression; ?>";
});
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.
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,
],
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/.
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.
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
Localization
The views use static text. For localization, wrap strings in __() and publish the language files:
php artisan vendor:publish --tag=laravel-translations
How can I help you explore Laravel packages today?