skagarwal / generators
Directory Structure Laravel 5.1 Generator.
Requires
- illuminate/console: ~5.1
- illuminate/container: ~5.1
- illuminate/filesystem: ~5.1
- illuminate/support: ~5.1
Requires (Dev)
- phpunit/phpunit: ~4.0
- skagarwal/reflection: ~1.0
This package is not auto-updated.
Last update: 2022-12-02 20:19:39 UTC
README
Laravel-5.1-Generators
If you like to keep your laravel appliaction in well formed structure and tired of making all the directories and subdirectories manually for every model, Then this package will help you automate this process.
This Package Strictly Follows The Directory Structure:
app/ | |_Foo/ | |_Foo.php // The Eloquent Model | |_Contracts/ | |_FooRepository.php // black interface | |_Events/ | |_Jobs/ | |_Listeners/ | |_Repositories/ | |_EloquentFooRepository.php // impletements the FooRepository.php interface out of the box.
**Avaiabale Commands:** - `create:model` - `create:repository` - `create:event` - `create:listener` - `create:job`
Few More to Come
Usage
Step 1: Install Through Composer
composer require skagarwal/generators --dev
Step 2: Add the Service Provider
Add the SKAgarwal\Generators\GeneratorsServiceProvider
to the Config/app.php
's providers
array
Config/app.php
'providers' => [
...
...
...
'SKAgarwal\Generators\GeneratorsServiceProvider',
],
Step 3: Run Artisan!
You're all set. Run php artisan
from the console, and you'll see the new commands in the make:*
namespace section.
create:model
Description:
- Creates a model, migration and the directory structure.
Arguments:
model
- Required. Name of the model to be created.
Options:
--migration
- Optional. If provided, Migration for the Model will be created.
usage:
php artisan create:model Foo ---migration
This will produce the Following:
app/ | |_Foo/ | |_Foo.php // The Eloquent Model | |_Contracts/ | |_FooRepository.php // black interface | |_Events/ | |_Policies/ | |_Jobs/ | |_Listeners/ | |_Repositories/ | |_EloquentFooRepository.php // impletements the FooRepository.php interface out of the box.
And since --migration
option is provided, there will be a migration for Foo
in Database\Migrations\
.
create:repository
Description:
- Creates a repository interface and its eloquent implimentation in respective directories.
Arguments:
model
- Required. The Model Name. Repository Will Be Created Under This Model Directory.
Options:
--repository
- Optional. The Repository Name to be created. If not provided, Repository with the Model Name will be created.
Usage:
php artisan create:repository Foo
This will produce:
app\Foo\Contracts\FooRepository.php app\Foo\Repositories\EloquentFooRepository.php
If --repository=Bar
or -r Bar
is provided, then it will produce:
app\Foo\Contracts\BarRepository.php app\Foo\Repositories\EloquentBarRepository.php
Note:
-
Do not forget to bind the interface to its implimentation in Service container.
create:event
Description:
- Creates a event class in
{model}/Events/
directory.
Arguments:
name
- Required. Name of the event class.
Options:
model
- Required. Name of the model the event belongs to.
Usage:
php artisan create:event UserRegistered --model=User
This will produce:
User\Events\UserRegistered.php
create:listener
Description:
- Creates a event listener in
{model}\Listeners\
directory.
Arguments:
name
- Required. Name of the event listener.
Options:
model
- Required. Name of the model lsitener belongs to.event
- Required. Name fo the event listener is being listened for.queued
- Optional Indicated listener should be queued.
Usage:
php artisan create:listener SendWelcomeEmail --event=UserRegistered --model=User
This will produce:
User\Listeners\SendWelcomeEmail.php
Note:
-
Do not forget to register the listener for the event in
EventServiceProvider
.
create:job
Description:
- Creates a job in
{model}\Jobs\
directory.
Arguments:
name
- Required. Name of the job.
Options:
model
- Required. Name of the model job belongs to.queued
- Optional Indicated listener should be queued.
Usage:
php artisan create:job RegisterUser --model=User --queued
This will produce:
User\Jobs\RegisterUser.php
create:policy
Description:
- Creates a policy in
{model}\Policies\
directory.
Arguments:
name
- Required. Name of the policy.
Options:
model
- Required. Name of the model policy belongs to.
Usage:
php artisan create:policy PostPolicy --model=Post
This will produce:
Post\Policies\PostPolicy.php