2017 © Pedro Peláez
 

library generators

Custom Laravel 5 File Generators with config and publishable stubs.

image

bpocallaghan/generators

Custom Laravel 5 File Generators with config and publishable stubs.

  • Thursday, March 22, 2018
  • by bpocallaghan
  • Repository
  • 8 Watchers
  • 62 Stars
  • 8,885 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 12 Forks
  • 3 Open issues
  • 41 Versions
  • 11 % Grown

The README.md

Laravel File Generators

Custom Laravel File Generators with a config file and publishable stubs. You can publish the stubs. You can add your own stubs to generate., (*1)

This package is being used in Admin Starter Project that focuses on test driven development and has the foundation ready for you., (*2)

Laravel 5.1 : v2.1.3
Laravel 5.2 - 5.3 : v3.0.3
Laravel 5.4 : v4.1.9
Laravel 5.5 - 5.8 : v5.0.0+
Laravel 6.0 : v5.1.0+
Laravel 7.0 : v6.x
Laravel 8.0 : v7.x
Laravel 9.0 : v8.x
Laravel 10.0 : v9.x

Commands

php artisan generate:publish-stubs
php artisan generate:model
php artisan generate:view
php artisan generate:controller
php artisan generate:migration
php artisan generate:migration:pivot
php artisan generate:seed
php artisan generate:resource
php artisan generate:repository
php artisan generate:contract
php artisan generate:notification
php artisan generate:event
php artisan generate:listener
php artisan generate:event-listener
php artisan generate:trait
php artisan generate:job
php artisan generate:console
php artisan generate:middleware
php artisan generate:factory
php artisan generate:test
php artisan generate:file
php artisan generate:exception
php artisan generate:component
php artisan generate:livewire

Option for all the commands

  • --force This will override the existing file, if it exists.
  • --test This will also generate a test file.

Option for all the commands, except views and migration:pivot

  • --plain This will use the .plain stub of the command (generate an empty controller)

Customization

This is for all except the migration and migration:pivot commands, (*3)

php artisan generate:file foo.bar --type=controller
php artisan generate:view foo.bar --stub=view_show --name=baz_show
php artisan generate:file foo.bar --type=controller --stub=controller_custom --name=BazzzController --plain --force

You can specify a custom name of the file to be generated. You can add the --plain or --force options. You can override the default stub to be used. You can create your own stubs with the available placeholders. You can create new settings' types, for example: - 'exception' => ['namespace' => '\Exceptions', 'path' => './app/Exceptions/', 'postfix' => 'Exception'],, (*4)

Available placeholders, (*5)

Views Custom Stubs

php artisan generate:view posts
php artisan generate:view admin.posts --stub=custom
php artisan generate:view admin.posts --stub=another_file

Installation

Update your project's composer.json file., (*6)

composer require bpocallaghan/generators --dev

Add the Service Provider (Laravel 5.5+ has automatic discovery of packages) You'll only want to use these generators for local development, add the provider in app/Providers/AppServiceProvider.php:, (*7)

public function register()
{
    if ($this->app->environment() == 'local') {
        $this->app->register(\Bpocallaghan\Generators\GeneratorsServiceProvider::class);
    }
}

Run php artisan command to see the new commands in the generate:* section, (*8)

Usage

Models

php artisan generate:model bar
php artisan generate:model foo.bar --plain
php artisan generate:model bar --force
php artisan generate:model bar --factory
php artisan generate:model bar --migration
php artisan generate:model bar --migration --schema="title:string, body:text"

Views

php artisan generate:view foo
php artisan generate:view foo.bar
php artisan generate:view foo.bar --stub=view_show
php artisan generate:view foo.bar --name=foo_bar

Controllers

php artisan generate:controller foo
php artisan generate:controller foo.bar
php artisan generate:controller fooBar
php artisan generate:controller bar --plain
php artisan generate:controller BarController --plain
  • The Controller postfix will be added if needed.

Migrations

This is very similar as Jeffrey Way's, (*9)

php artisan generate:migration create_users_table
php artisan generate:migration create_users_table --plain
php artisan generate:migration create_users_table --force
php artisan generate:migration create_posts_table --schema="title:string, body:text, slug:string:unique, published_at:date"

Pivot Tables

This is very similar as Jeffrey Way's, (*10)

php artisan generate:migration:pivot tags posts

Database Seeders

php artisan generate:seed bar
php artisan generate:seed BarTableSeeder
  • The TableSeeder suffix will be added if needed.

Resource

php artisan generate:resource bar
php artisan generate:resource foo.bar
php artisan generate:resource foo.bar_baz
php artisan generate:resource bar --schema="title:string, body:text, slug:string:unique, published_at:date"
php artisan generate:resource articles --controller=admin
  • This will generate a Bar model, BarsController, resources views (in config), create_bars_table migration, BarTableSeeder
  • In the config there is a resource_views array, you can specify the views that you want to generate there, just make sure the stub exist.
  • This will also ask you to generate the 'repository - contract pattern' files.
  • The --controller=admin allows you to use the controller_admin stub when generating the controller.

Repository

php artisan generate:repository Posts

This will generate a Posts Repository file to be used in your controller., (*11)

Contract

php artisan generate:contract Cache

This will generate a Cache Contract file to be used with your repositories., (*12)

Notifications

php artisan generate:notification UserRegistered

This will generate a UserRegistered notification. Laravel provides support for sending notifications across a variety of delivery channels, including mail, SMS (via Nexmo), and Slack. Notifications may also be stored in a database so they may be displayed in your web interface., (*13)

Events and Listeners

php artisan generate:event InvoiceWasPaid
php artisan generate:listener NotifyUserAboutPayment --event=InvoiceWasPaid
php artisan generate:event-listener

This will generate the event and listener. Laravel's events provides a simple observer implementation, allowing you to subscribe and listen for various events that occur in your application, (*14)

php artisan generate:event-listener Will generate all the missing events and listeners defined in your EventServiceProvider., (*15)

Trait

php artisan generate:trait Http\Controllers\Traits\Bar

This will generate a FooBar Trait file. The command will use the name as your namespace. generate:trait Foo will create a file in app/Foo.php, generate:trait Foo\Bar will create a file in app/Foo/Bar.php., (*16)

Job

php artisan generate:job SendReminderEmail

This will generate a SendReminderEmail Job file., (*17)

Console (Artisan Command)

php artisan generate:console SendEmails
php artisan generate:console SendEmails --command=send:emails

This will generate a SendEmails Artisan Command file. The --command option is optional., (*18)

Middleware

php artisan generate:middleware AuthenticateAdmin

This will generate an AuthenticateAdmin Middleware file., (*19)

Factory

php artisan generate:factory Post
php artisan generate:factory PostFactory

This will generate a PostFactory model file., (*20)

Test

php artisan generate:test UserCanLogin
php artisan generate:test Post --unit
php artisan generate:test Auth\LoginTest

This will generate Feature\UserCanLogin and Unit\PostTest and Unit\Auth\LoginTest files., (*21)

Component

php artisan generate:component Foo
php artisan generate:component Foo/Bar
php artisan generate:component Baz --test

This will generate a Laravel Component. The php and blade files will be generated. You can also specify to generate a unit test., (*22)

Livewire

php artisan generate:livewire Foo
php artisan generate:livewire Foo/Bar
php artisan generate:livewire Baz --test
php artisan generate:livewire foo-bar --request

This will generate a Livewire component. The php and blade files will be generated. You can also specify to generate a test or a form request., (*23)

Configuration

php artisan generate:publish-stubs

This will copy the config file to /config/generators.php. Here you can change the defaults for the settings of each type, like model, view, controller, seed. You can also change the namespace, path where to create the file, the pre/post fix, and more. You can also add new stubs., (*24)

This will also copy all the stubs to /resources/stubs/. Here you can make changes to the current stubs, add your own boilerplate / comments to the files. You can also add your own stubs here and specify it in the config to be used. Migration Stub Note: The migration.stub is only the outer part and the schema_create.stub or schema_change.stub is where you modify the schema itself. The schema_create.stub has boilerplate added to it., (*25)

File

This is the base command for the view, model, controller, seed commands. The migration and migration:pivot uses Jeffrey's classes. In the config there is a settings array, this is the 'types' and their settings. You can add more, for example, if you use repositories, you can add it here., (*26)

php artisan generate:file foo.bar --type=view
php artisan generate:file foo.bar --type=controller
php artisan generate:file foo.bar --type=model
php artisan generate:file foo.bar --type=model --stub=model_custom

Customizing file was created message to add support for ide opening the files

Make links for opening output. Add output_path_handler as a function to your config/generators.php.Example:, (*27)

'output_path_handler' => static function($path){
    return 'file:///' . base_path() . $path;
},

This will output a file schema uri which JetBrain Products (Intellij,Php Storm,Web Storm,...) then can open directly from your terminal., (*28)

Thank you

My Other Packages

  • Alert A helper package to flash a bootstrap alert to the browser via a Facade or a helper function.
  • Notify Laravel Flash Notifications with icons and animations and with a timeout
  • Impersonate User This allows you to authenticate as any of your customers.
  • Sluggable Provides a HasSlug trait that will generate a unique slug when saving your Laravel Eloquent model.

The Versions

22/03 2018

dev-master

9999999-dev

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel config generators commands stubs customization

12/02 2018

5.0.2

5.0.2.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel config generators commands stubs customization

16/11 2017

5.0.1

5.0.1.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel config generators commands stubs customization

20/09 2017

5.0.0

5.0.0.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel config generators commands stubs customization

20/09 2017

4.0.x-dev

4.0.9999999.9999999-dev

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

16/08 2017

4.1.9

4.1.9.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

08/08 2017

4.1.8

4.1.8.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

01/08 2017

4.1.7

4.1.7.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

29/07 2017

4.1.6

4.1.6.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

28/07 2017

4.1.5

4.1.5.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

19/07 2017

4.1.4

4.1.4.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

12/07 2017

3.0.x-dev

3.0.9999999.9999999-dev

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

12/07 2017

3.0.3

3.0.3.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

11/07 2017

4.1.3

4.1.3.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

08/07 2017

4.1.2

4.1.2.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

laravel config generators commands stubs customization

01/07 2017

4.1.1

4.1.1.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

20/06 2017

4.1.0

4.1.0.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

15/05 2017

4.0.9

4.0.9.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

15/05 2017

4.0.8

4.0.8.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

11/05 2017

4.0.7

4.0.7.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

11/05 2017

4.0.6

4.0.6.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

05/05 2017

4.0.5

4.0.5.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

05/05 2017

4.0.4

4.0.4.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

03/05 2017

4.0.3

4.0.3.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

02/05 2017

4.0.2

4.0.2.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

02/05 2017

4.0.1

4.0.1.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

09/03 2017

4.0.0

4.0.0.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

03/10 2016

3.0.2

3.0.2.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

02/04 2016

3.0.1

3.0.1.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

10/03 2016

3.0.0

3.0.0.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

07/10 2015

2.0.x-dev

2.0.9999999.9999999-dev

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

07/10 2015

2.1.3

2.1.3.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

07/10 2015

2.1.2

2.1.2.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

06/10 2015

2.1.1

2.1.1.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

19/09 2015

2.1.0

2.1.0.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

09/09 2015

2.0.1

2.0.1.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

17/05 2015

2.0.0

2.0.0.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

16/04 2015

1.0.3

1.0.3.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

11/04 2015

1.0.2

1.0.2.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

11/04 2015

1.0.1

1.0.1.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators

11/04 2015

1.0.0

1.0.0.0

Custom Laravel 5 File Generators with config and publishable stubs.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel generators