Skip to content

Commit

Permalink
added model skeleton; added opitional api files
Browse files Browse the repository at this point in the history
  • Loading branch information
flavianohonorato committed Aug 25, 2019
1 parent 90613b6 commit de6b95b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
56 changes: 47 additions & 9 deletions src/Modularization/Bake/Console/Commands/BakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

class BakeCommand extends Command
{
protected $signature = 'bake:module {name}';
protected $signature = 'bake:module {name : The module name} {--api : scaffolding like api}';
protected $description = 'Create a new module skeleton, use the plural name in lowercase and underscore separator';

protected $singular_name;
protected $plural_name;
protected $prefix;
protected $routes;

public function handle()
{
Expand All @@ -23,8 +25,18 @@ public function handle()
throw new \Exception('This modules exists!');
}

$this->routes = [
'web.php',
];

if ($this->option('api')) {
$this->prefix = 'api';
array_push($this->routes, 'api.php');
}

$directories = [
'Controllers',
'Models',
'Migrations',
'Providers',
'Routes',
Expand All @@ -35,8 +47,7 @@ public function handle()
'controller' => 'Controller.php',
'provider' => 'ServiceProvider.php',
'route' => [
'api.php',
'web.php',
$this->routes
],
'view' => 'index.blade.php',
];
Expand All @@ -49,15 +60,42 @@ public function handle()

$origin = $base_dir.'Bake/bake_template/';

$this->createFile($origin . '/Controllers/Controller.php', $base_dir . studly_case($this->plural_name) . '/Controllers/' . studly_case($this->plural_name) . 'Controller.php');
$this->createFile($origin . '/Providers/ServiceProvider.php', $base_dir . studly_case($this->plural_name) . '/Providers/' . studly_case($this->singular_name) . 'ServiceProvider.php');
$this->createFile($origin . '/Routes/api.php', $base_dir . studly_case($this->plural_name) . '/Routes/api.php');
$this->createFile($origin . '/Routes/web.php', $base_dir . studly_case($this->plural_name) . '/Routes/web.php');
$this->createFile($origin . '/Views/index.blade.php', $base_dir . studly_case($this->plural_name) . '/Views/index.blade.php');
$this->createFile(
$origin . '/Controllers/Controller.php', $base_dir . studly_case($this->plural_name) .
'/Controllers/' . studly_case($this->plural_name) . 'Controller.php'
);

$this->createFile(
$origin . '/Models/Model.php', $base_dir . studly_case($this->singular_name) .
'/Models/' . studly_case($this->singular_name) . '.php'
);

$this->createFile(
$origin . '/Providers/ServiceProvider.php', $base_dir . studly_case($this->plural_name) .
'/Providers/' . studly_case($this->singular_name) . 'ServiceProvider.php'
);

if ($this->option('api')) {
$this->createFile(
$origin . '/Routes/api.php', $base_dir . studly_case($this->plural_name) .
'/Routes/api.php'
);
} else {
$this->createFile(
$origin . '/Routes/web.php', $base_dir . studly_case($this->plural_name) .
'/Routes/web.php'
);
}

$this->createFile(
$origin . '/Views/index.blade.php', $base_dir . studly_case($this->plural_name) .
'/Views/index.blade.php'
);

$this->output->writeln([
'Add this provider to config/app.php:',
'Modules\\' . studly_case($this->plural_name) . '\Providers\\' . studly_case($this->singular_name) . 'ServiceProvider::class,'
'Modules\\' . studly_case($this->plural_name) . '\Providers\\' .
studly_case($this->singular_name) . 'ServiceProvider::class,'
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class {{plural-upper}}Controller extends Controller
{

/**
use \App\Http\Controllers\ApiControllerTrait; //for APIs
use \App\Http\Controllers\CrudControllerTrait; //for dashboards
protected $model;
protected $path = '{{singular-upper}}::';
protected $redirectPath = '{{plural-lower}}'; //delete it for ApiCrudControllerTrait
Expand Down
11 changes: 11 additions & 0 deletions src/Modularization/Bake/bake_template/Models/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Modularization\{{plural-upper}}\Models;

use Illuminate\Database\Eloquent\Model;

class {{plural-upper}} extends Model
{
protected $table = '';
protected $fillable = [''];
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function webRoutes()
protected function apiRoutes()
{
if (!$this->app->routesAreCached()) {
Route::prefix('api')
Route::prefix('api/{{plural-lower}}')
->namespace($this->namespace)
->group(__DIR__ . '/../Routes/api.php');
}
Expand Down

0 comments on commit de6b95b

Please sign in to comment.