mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2024-12-25 13:35:28 +03:00
Added Laravel Routes
- New template - Command updates
This commit is contained in:
parent
dafa7f2f22
commit
a2cf22d426
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ tests/_output/*
|
||||
lumen-test/app
|
||||
lumen-test/database
|
||||
lumen-test/tests/tmp
|
||||
|
||||
.idea
|
||||
|
4
lumen-test/.gitignore
vendored
4
lumen-test/.gitignore
vendored
@ -4,4 +4,6 @@
|
||||
tests/_output/*
|
||||
|
||||
composer.lock
|
||||
tests/_output/*
|
||||
tests/_output/*
|
||||
|
||||
codecept.phar
|
||||
|
@ -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
|
||||
|
7
lumen-test/routes/api.php
Normal file
7
lumen-test/routes/api.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
|------------------------------------------
|
||||
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|
||||
|------------------------------------------
|
||||
*/
|
||||
|
@ -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')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
8
templates/routes-laravel.wnt
Normal file
8
templates/routes-laravel.wnt
Normal 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');
|
Loading…
Reference in New Issue
Block a user