Added Laravel Routes

- New template
- Command updates
This commit is contained in:
Josiah Dahl 2017-08-06 16:45:16 -07:00
parent dafa7f2f22
commit a2cf22d426
9 changed files with 49 additions and 6 deletions

2
.gitignore vendored
View File

@ -7,3 +7,5 @@ tests/_output/*
lumen-test/app
lumen-test/database
lumen-test/tests/tmp
.idea

View File

@ -4,4 +4,6 @@
tests/_output/*
composer.lock
tests/_output/*
tests/_output/*
codecept.phar

View File

@ -11,6 +11,14 @@ echo "<?php
return \$app->welcome();
});" > app/Http/routes.php
echo "<?php
/*
|------------------------------------------
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|------------------------------------------
*/
" > routes/api.php
# Controllers
rm app/Http/Controllers/*.php 2> /dev/null
echo "<?php

View File

@ -0,0 +1,7 @@
<?php
/*
|------------------------------------------
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|------------------------------------------
*/

View File

@ -7,6 +7,8 @@ class ControllerCommand extends BaseCommand {
{model : Name of the model (with namespace if not App)}
{--no-routes= : without routes}
{--force= : override the existing files}
{--laravel= : Boolean (default false) Use Laravel style route definitions}
';
protected $description = 'Generates RESTful controller using the RESTActions trait';
@ -35,7 +37,8 @@ class ControllerCommand extends BaseCommand {
if(! $this->option('no-routes')){
$this->call('wn:route', [
'resource' => snake_case($name, '-'),
'--controller' => $controller
'--controller' => $controller,
'--laravel' => $this->options('laravel')
]);
}
}

View File

@ -15,6 +15,7 @@ class ResourceCommand extends BaseCommand {
{--path=app : where to store the model file.}
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}
{--force= : override the existing files}
{--laravel= : Boolean (default false) Use Laravel style route definitions}
';
protected $description = 'Generates a model, migration, controller and routes for RESTful resource';
@ -66,7 +67,8 @@ class ResourceCommand extends BaseCommand {
$this->call('wn:controller', [
'model' => $modelName,
'--force' => $this->option('force'),
'--no-routes' => false
'--no-routes' => false,
'--laravel' => $this->option('laravel')
]);
// generating model factory

View File

@ -9,6 +9,8 @@ class ResourcesCommand extends BaseCommand {
{file : Path to the file containing resources declarations}
{--path=app : where to store the model files.}
{--force= : override the existing files}
{--laravel= : Boolean (default false) Use Laravel style route definitions}
';
protected $description = 'Generates multiple resources from a file';
@ -32,7 +34,8 @@ class ResourcesCommand extends BaseCommand {
'--belongs-to' => $i['belongsTo'],
'--belongs-to-many' => $i['belongsToMany'],
'--path' => $this->option('path'),
'--force' => $this->option('force')
'--force' => $this->option('force'),
'--laravel' => $this->option('laravel')
]);
}

View File

@ -5,21 +5,29 @@ class RouteCommand extends BaseCommand {
protected $signature = 'wn:route
{resource : Name of the resource.}
{--controller= : Name of the RESTful controller.}';
{--controller= : Name of the RESTful controller.}
{--laravel= : Boolean (default false) Use Laravel style route definitions
';
protected $description = 'Generates RESTful routes.';
public function handle()
{
$resource = $this->argument('resource');
$laravelRoutes = $this->option('laravel');
$templateFile = 'routes';
$routesPath = './routes/web.php';
if ($laravelRoutes) {
$routesPath = './routes/api.php';
$templateFile = 'routes-laravel';
}
if (! $this->fs->exists($routesPath))
$routesPath = './app/Http/routes.php';
$content = $this->fs->get($routesPath);
$content .= PHP_EOL . $this->getTemplate('routes')
$content .= PHP_EOL . $this->getTemplate($templateFile)
->with([
'resource' => $resource,
'controller' => $this->getController()

View File

@ -0,0 +1,8 @@
/**
* Routes for resource {{resource}}
*/
Route::get('{{resource}}', '{{controller}}@all');
Route::get('{{resource}}/{id}', '{{controller}}@get');
Route::post('{{resource}}', '{{controller}}@add');
Route::put('{{resource}}/{id}', '{{controller}}@put');
Route::delete('{{resource}}/{id}', '{{controller}}@remove');