Laravel CRUD Templates - Generate complete CRUD operations with a single command
jcsoriano/laravel-crud-templates is a Laravel package for laravel crud templates - generate complete crud operations with a single command.
It currently has 4 GitHub stars and 1 downloads on Packagist (latest version v1.5.0).
Install it with composer require jcsoriano/laravel-crud-templates.
Discover more Laravel packages by jcsoriano
or browse all Laravel packages to compare alternatives.
Last updated
CRUD Templates for Laravel allows you to generate controllers, models, policies, requests, resources, migrations, factories, and even tests - all the files you need to complete CRUD features with a single command.
You can completely modify the template or create your own templates to fit your project's conventions perfectly.

You can install the package via Composer as a dev dependency:
composer require --dev jcsoriano/laravel-crud-templates
The package will automatically register itself via Laravel's package discovery.
You can publish the stubs to customize them:
php artisan vendor:publish --tag="crud-templates-stubs"
To generate a CRUD feature, you may use this command:
php artisan crud:generate
{model : The name of the model}
{--fields= : The fields to generate. Format: field1:type1,field2?:type2}
{--table= : The database table to generate the fields from}
{--template=api : The CRUD template to generate}
{--skip= : List of files you want to skip}
{--options= : Other options to pass to the generator. Format: key1:value1,key2:value2}
{--force : Overwrite existing files}
Sample command to generate a fully functioning RESTful API:
php artisan crud:generate Content/Post --template=api --fields="title:string,content:text,published_at:datetime,category:belongsTo,comments:hasMany,status:enum:PublishStatus" --options="scope:user"
This command generates all the files needed to complete the CRUD feature, from routes, to validation, to authorization, to API responses, to migrations, to factories, to tests, and more.
app/Http/Controllers/Api/Content/PostController.phpapp/Models/Content/Post.phpapp/Policies/PostPolicy.phpapp/Http/Requests/Content/StorePostRequest.phpapp/Http/Requests/Content/UpdatePostRequest.phpapp/Http/Resources/Content/PostResource.phpdatabase/migrations/{timestamp}_create_posts_table.phpdatabase/migrations/{timestamp}_create_{pivot}_tables.php (if belongsToMany or morphToMany relationships are present)database/factories/Content/PostFactory.phptests/Feature/Api/Content/PostControllerTest.phproutes/api.php (will run install:api if the file doesn't exist yet)The command automatically registers the following routes in your routes/api.php file:
| HTTP Method | URI | Action | Description |
|-------------|-----|--------|-------------|
| GET | /api/posts | index | List all posts (paginated) |
| POST | /api/posts | store | Create a new post |
| GET | /api/posts/{id} | show | Show a specific post |
| PUT/PATCH | /api/posts/{id} | update | Update a post |
| DELETE | /api/posts/{id} | destroy | Delete a post |
{
"data": {
"id": 1,
"title": "My Post",
"content": "...",
"category": { "...": "..." },
"comments": [ { "...": "..." } ],
"status": "published",
"published_at": "2024-01-01T00:00:00.000000Z",
"created_at": "2024-01-01T00:00:00.000000Z",
"updated_at": "2024-01-01T00:00:00.000000Z"
}
}
{
"data": [
{ "The Post object as above" },
],
"links": { "first": "...", "last": "...", "prev": null, "next": "..." },
"meta": { "current_page": 1, "per_page": 15, "total": 50 }
}
The request classes automatically include appropriate validation:
StorePostRequest:
public function rules(): array
{
return [
'title' => ['required', 'string', 'max:255'],
'content' => ['required', 'string'],
'published_at' => ['required', 'date'],
'category_id' => ['bail', 'required', 'exists:categories,id'],
'status' => ['required', Rule::enum(PublishStatus::class)],
];
}
The generated Post model will include several automatic enhancements:
Relationship Methods:
public function category(): BelongsTo
{
return $this->belongsTo(Category::class);
}
public function comments(): HasMany
{
return $this->hasMany(Comment::class);
}
Type Casting:
protected $casts = [
'published_at' => 'immutable_datetime', // Automatic datetime casting
'status' => PublishStatus::class, // Enum casting
];
Fillable Fields:
protected $fillable = [
'title',
'content',
'published_at',
'category_id',
'status',
];
The migration includes proper foreign key constraints:
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('content');
$table->dateTime('published_at');
$table->foreignId('category_id')->constrained();
$table->string('status');
$table->timestamps();
});
The generated PostResource automatically includes relationships:
public function toArray($request): array
{
return [
...
'category' => CategoryResource::make($this->whenLoaded('category')),
'comments' => CommentResource::collection($this->whenLoaded('comments')),
];
}
If you find this package useful and would like to support its development, consider supporting me through one of these platforms:
Your support helps me continue building and maintaining this package. Thank you! 🙏
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.