Commit 2cec8f26 authored by kay899's avatar kay899 Committed by Nicolas Widart

Extend EntityGenerator with Request files (#350)

* Update EntityGenerator.php

* Create Request file

* Update Request file

* Request file changes in Admin Controller

* Test for generating Request files
parent 6990155e
......@@ -56,6 +56,7 @@ class EntityGenerator extends Generator
}
$this->generateRepositoriesFor($entity);
$this->generateControllerFor($entity);
$this->generateRequestsFor($entity);
$this->generateViewsFor($entity);
$this->generateLanguageFilesFor($entity);
$this->appendBindingsToServiceProviderFor($entity);
......@@ -107,6 +108,27 @@ class EntityGenerator extends Generator
$this->getContentForStub('admin-controller.stub', $entity)
);
}
/**
* Generate the requests for the given entity
*
* @param string $entity
*/
private function generateRequestsFor($entity)
{
$path = $this->getModulesPath('Http/Requests');
if (! $this->finder->isDirectory($path)) {
$this->finder->makeDirectory($path);
}
$this->writeFile(
$this->getModulesPath("Http/Requests/Create{$entity}Request"),
$this->getContentForStub('create-request.stub', $entity)
);
$this->writeFile(
$this->getModulesPath("Http/Requests/Update{$entity}Request"),
$this->getContentForStub('update-request.stub', $entity)
);
}
/**
* Generate views for the given entity
......
......@@ -5,6 +5,8 @@ namespace Modules\$MODULE_NAME$\Http\Controllers\Admin;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\$MODULE_NAME$\Entities\$CLASS_NAME$;
use Modules\$MODULE_NAME$\Http\Requests\Create$CLASS_NAME$Request;
use Modules\$MODULE_NAME$\Http\Requests\Update$CLASS_NAME$Request;
use Modules\$MODULE_NAME$\Repositories\$CLASS_NAME$Repository;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
......@@ -50,7 +52,7 @@ class $CLASS_NAME$Controller extends AdminBaseController
* @param Request $request
* @return Response
*/
public function store(Request $request)
public function store(Create$CLASS_NAME$Request $request)
{
$this->$LOWERCASE_CLASS_NAME$->create($request->all());
......@@ -76,7 +78,7 @@ class $CLASS_NAME$Controller extends AdminBaseController
* @param Request $request
* @return Response
*/
public function update($CLASS_NAME$ $$LOWERCASE_CLASS_NAME$, Request $request)
public function update($CLASS_NAME$ $$LOWERCASE_CLASS_NAME$, Update$CLASS_NAME$Request $request)
{
$this->$LOWERCASE_CLASS_NAME$->update($$LOWERCASE_CLASS_NAME$, $request->all());
......
<?php
namespace Modules\$MODULE_NAME$\Http\Requests;
use Modules\Core\Internationalisation\BaseFormRequest;
class Create$CLASS_NAME$Request extends BaseFormRequest
{
public function rules()
{
return [];
}
public function translationRules()
{
return [];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
public function translationMessages()
{
return [];
}
}
<?php
namespace Modules\$MODULE_NAME$\Http\Requests;
use Modules\Core\Internationalisation\BaseFormRequest;
class Update$CLASS_NAME$Request extends BaseFormRequest
{
public function rules()
{
return [];
}
public function translationRules()
{
return [];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
public function translationMessages()
{
return [];
}
}
......@@ -299,6 +299,20 @@ class ModuleScaffoldTest extends BaseTestCase
$this->cleanUp();
}
/** @test */
public function it_should_generate_requests()
{
$this->scaffoldModuleWithEloquent(['Post']);
$file1 = $this->finder->isFile($this->testModulePath . '/Http/Requests/CreatePostRequest.php');
$file2 = $this->finder->isFile($this->testModulePath . '/Http/Requests/UpdatePostRequest.php');
$this->assertTrue($file1);
$this->assertTrue($file2);
$this->cleanUp();
}
/** @test */
public function it_should_generate_routes_file()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment