akoepcke/laravel-spawn

This package is abandoned and no longer maintained. No replacement package was suggested.

Laravel package to generate CRUD and view files

0.2 2018-11-13 14:52 UTC

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 commands
  • php artisan spawn:model {model} will create a {Model}.php
  • php artisan spawn:controller {model} will create {Model}Controller.php and Trashed{Model}Controller.php
  • php artisan spawn:test {model} will create several feature tests for the controllers
  • php artisan spawn:policy {model} will create {Model}Policy.php
  • php artisan spawn:role {model} will create an administrative role with basic CRUD permissions
  • php artisan spawn:view {model} will create {Model}Policy.php and register it in AuthServiceProvider
  • php artisan spawn:database {model} will create migration, factory and seed files, and register the seed in DatabaseSeeder
  • php 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

License

The MIT License (MIT). Please see License File for more information.