akoepcke / laravel-spawn
Laravel package to generate CRUD and view files
Requires
- php: ~7.0
- illuminate/support: ^5.6
- symfony/process: ^4.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
This package is auto-updated.
Last update: 2020-08-29 05:07:32 UTC
README
This package provides some Laravel commands to help speed up Laravel development by generating several often needed files. It complements my Laravel-Skeleton.
Features
- create soft-deletable model with Uuid
- create ModelController and TrashedModelController
- create default feature tests for ModelController and TrashedModelController
- create and register ModelPolicy
- register Role and Permissions
- create model/[create,edit,index].blade.php
- create trashedModel/index.blade.php
- create and register DB migration, factory and seed files
- register routes and route model binding in Routes/web.php
The following features are planned for SomedayTM
- register route model binding in RouteServiceProvider
- make uuid flaggable
Installation
You can install the package via composer:
composer require "akoepcke/laravel-spawn"
Usage
Run the following to publish the config file to config/spawn.php
php artisan vendor:publish --provider="AKoepcke\LaravelSpawn\ServiceProvider" --tag="stubs""
Run the following to publish the file stubs to resources/stubs
php artisan vendor:publish --provider="AKoepcke\LaravelSpawn\ServiceProvider" --tag="config""
This package provides the following commands:
php artisan spawn:monster {model}
will run through all of spawn's commandsphp artisan spawn:model {model}
will create a {Model}.phpphp artisan spawn:controller {model}
will create {Model}Controller.php and Trashed{Model}Controller.phpphp artisan spawn:test {model}
will create several feature tests for the controllersphp artisan spawn:policy {model}
will create {Model}Policy.phpphp artisan spawn:role {model}
will create an administrative role with basic CRUD permissionsphp artisan spawn:view {model}
will create {Model}Policy.php and register it in AuthServiceProviderphp artisan spawn:database {model}
will create migration, factory and seed files, and register the seed in DatabaseSeederphp artisan spawn:route {model}
will create CRUD routes and route model binding
Attention: Most commands will overwrite existing files. Some commands, like spawn:route
, will append to existing files.There are also commands, such as the registration of seeders, that will insert into existing files.
Gotchas
- This package supplements my Laravel-Skeleton which has already some stuff installed. Several spawn commands will fail without the proper setup.
- This package will register some routes in your routes/web.php.
You might want to protect these routes by wrapping them into an auth-protected group.
I also use this group to assign a route admin prefix.
Route::group(['prefix' => 'admin', 'middleware' => 'auth']), function() { // copy here }
- Some PHPUnit tests will fail if the spawned routes are not auth-middleware-checked.
- Also, I like to cut/paste the route model binding to the top of the routes file. Other people prefer to put it into app/Providers/RouteServiceProvider.php
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- Anne Köpcke
- This package is inspired by work shown in an article called Laravel CRUD generator from Scratch
- Shoutout also to Sander van Hooft for his Laravel package development from scratch email course
License
The MIT License (MIT). Please see License File for more information.