├── .gitignore
├── Console
├── ConsoleCommand.php
├── ControllerCommand.php
├── FormCommand.php
├── MigrationCommand.php
├── ModelCommand.php
├── PivotCommand.php
├── RequestCommand.php
├── ScaffoldCommand.php
├── SeedCommand.php
└── ViewCommand.php
├── ConsoleGenerator.php
├── ControllerGenerator.php
├── FileAlreadyExistsException.php
├── FormDumpers
├── FieldsDumper.php
├── StubTrait.php
└── TableDumper.php
├── FormGenerator.php
├── Generator.php
├── GeneratorsServiceProvider.php
├── LICENSE
├── MigrationGenerator.php
├── Migrations
├── NameParser.php
└── SchemaParser.php
├── ModelGenerator.php
├── PivotGenerator.php
├── README.md
├── RequestGenerator.php
├── ScaffoldGenerator.php
├── Scaffolders
└── ControllerScaffolder.php
├── SeedGenerator.php
├── Stub.php
├── Stubs
├── blank.stub
├── console.stub
├── controller
│ ├── plain.stub
│ ├── resource.stub
│ └── scaffold.stub
├── filter.stub
├── form
│ ├── checkbox.stub
│ ├── email.stub
│ ├── input.stub
│ ├── password.stub
│ ├── radio.stub
│ ├── select.stub
│ ├── text.stub
│ └── textarea.stub
├── migration
│ ├── add.stub
│ ├── create.stub
│ ├── delete.stub
│ ├── drop.stub
│ ├── pivot.stub
│ └── plain.stub
├── model.stub
├── provider.stub
├── request.stub
├── scaffold
│ ├── row.stub
│ └── views
│ │ ├── create.stub
│ │ ├── edit.stub
│ │ ├── form.stub
│ │ ├── index.stub
│ │ └── show.stub
├── seed.stub
├── view.stub
└── views
│ └── master.stub
├── ViewGenerator.php
├── composer.json
└── config.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.phar
3 | composer.lock
4 | .DS_Store
5 | /.idea
--------------------------------------------------------------------------------
/Console/ConsoleCommand.php:
--------------------------------------------------------------------------------
1 | $this->argument('name'),
35 | 'force' => $this->option('force'),
36 | 'command' => $this->option('command'),
37 | 'description' => $this->option('description'),
38 | ]);
39 |
40 | $this->info('Console created successfully.');
41 | } catch (FileAlreadyExistsException $e) {
42 | $this->comment($e->getMessage());
43 | }
44 | }
45 |
46 | /**
47 | * The array of command arguments.
48 | *
49 | * @return array
50 | */
51 | public function getArguments()
52 | {
53 | return [
54 | ['name', InputArgument::REQUIRED, 'The name of class being generated.', null],
55 | ];
56 | }
57 |
58 | /**
59 | * The array of command options.
60 | *
61 | * @return array
62 | */
63 | public function getOptions()
64 | {
65 | return [
66 | ['command', 'c', InputOption::VALUE_OPTIONAL, 'The name of command being used.', null],
67 | ['description', 'd', InputOption::VALUE_OPTIONAL, 'The description of command being used.', null],
68 | ['force', 'f', InputOption::VALUE_NONE, 'Force the creation if file already exists.', null],
69 | ];
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Console/ControllerCommand.php:
--------------------------------------------------------------------------------
1 | $this->argument('name'),
35 | 'resource' => $this->option('resource'),
36 | 'scaffold' => $this->option('scaffold'),
37 | 'force' => $this->option('force'),
38 | ]);
39 |
40 | $this->info('Controller created successfully.');
41 | } catch (FileAlreadyExistsException $e) {
42 | $this->comment($e->getMessage());
43 | }
44 | }
45 |
46 | /**
47 | * The array of command arguments.
48 | *
49 | * @return array
50 | */
51 | public function getArguments()
52 | {
53 | return [
54 | ['name', InputArgument::REQUIRED, 'The name of class being generated.', null],
55 | ];
56 | }
57 |
58 | /**
59 | * The array of command options.
60 | *
61 | * @return array
62 | */
63 | public function getOptions()
64 | {
65 | return [
66 | ['resource', 'r', InputOption::VALUE_NONE, 'Generate a resource controller.', null],
67 | ['scaffold', 's', InputOption::VALUE_NONE, 'Generate a scaffold controller.', null],
68 | ['force', 'f', InputOption::VALUE_NONE, 'Force the creation if file already exists.', null],
69 | ];
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Console/FormCommand.php:
--------------------------------------------------------------------------------
1 | argument('table'),
33 | $this->option('fields')
34 | );
35 |
36 | $this->line($generator->render());
37 | }
38 |
39 | /**
40 | * The array of command arguments.
41 | *
42 | * @return array
43 | */
44 | public function getArguments()
45 | {
46 | return [
47 | ['table', InputArgument::OPTIONAL, 'The name of table being used.', null],
48 | ];
49 | }
50 |
51 | /**
52 | * The array of command options.
53 | *
54 | * @return array
55 | */
56 | public function getOptions()
57 | {
58 | return [
59 | ['fields', 'f', InputOption::VALUE_OPTIONAL, 'The form fields.', null],
60 | ];
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Console/MigrationCommand.php:
--------------------------------------------------------------------------------
1 | $this->argument('name'),
36 | 'fields' => $this->option('fields'),
37 | 'force' => $this->option('force'),
38 | 'existing' => $this->option('existing'),
39 | ]);
40 |
41 | $this->info('Migration created successfully.');
42 |
43 | $composer->dumpAutoloads();
44 | } catch (FileAlreadyExistsException $e) {
45 | $this->comment($e->getMessage());
46 | }
47 | }
48 |
49 | /**
50 | * The array of command arguments.
51 | *
52 | * @return array
53 | */
54 | public function getArguments()
55 | {
56 | return [
57 | ['name', InputArgument::REQUIRED, 'The name of class being generated.', null],
58 | ];
59 | }
60 |
61 | /**
62 | * The array of command options.
63 | *
64 | * @return array
65 | */
66 | public function getOptions()
67 | {
68 | return [
69 | ['fields', 'c', InputOption::VALUE_OPTIONAL, 'The fields of migration. Separated with comma (,).', null],
70 | ['existing', 'e', InputOption::VALUE_NONE, 'Create migration from an existing table.', null],
71 | ['force', 'f', InputOption::VALUE_NONE, 'Force the creation if file already exists.', null],
72 | ];
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Console/ModelCommand.php:
--------------------------------------------------------------------------------
1 | $this->argument('name'),
35 | 'fillable' => $this->option('fillable'),
36 | 'force' => $this->option('force'),
37 | ]);
38 | $this->info('Model created successfully.');
39 | } catch (FileAlreadyExistsException $e) {
40 | $this->comment($e->getMessage());
41 | }
42 | }
43 |
44 | /**
45 | * The array of command arguments.
46 | *
47 | * @return array
48 | */
49 | public function getArguments()
50 | {
51 | return [
52 | ['name', InputArgument::REQUIRED, 'The name of class being generated.', null],
53 | ];
54 | }
55 |
56 | /**
57 | * The array of command options.
58 | *
59 | * @return array
60 | */
61 | public function getOptions()
62 | {
63 | return [
64 | ['fillable', null, InputOption::VALUE_OPTIONAL, 'The fillable attributes.', null],
65 | ['force', 'f', InputOption::VALUE_NONE, 'Force the creation if file already exists.', null],
66 | ];
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Console/PivotCommand.php:
--------------------------------------------------------------------------------
1 | $this->argument('table_one'),
33 | 'table_two' => $this->argument('table_two'),
34 | 'timestamp' => $this->option('timestamp'),
35 | 'force' => $this->option('force'),
36 | ]);
37 |
38 | $generator->run();
39 |
40 | $this->info('Migration created successfully.');
41 | }
42 |
43 | /**
44 | * The array of command arguments.
45 | *
46 | * @return array
47 | */
48 | public function getArguments()
49 | {
50 | return [
51 | ['table_one', InputArgument::REQUIRED, 'The name of table one.', null],
52 | ['table_two', InputArgument::REQUIRED, 'The name of table two.', null],
53 | ];
54 | }
55 |
56 | /**
57 | * The array of command options.
58 | *
59 | * @return array
60 | */
61 | public function getOptions()
62 | {
63 | return [
64 | ['timestamp', 't', InputOption::VALUE_NONE, 'Add timestamp to migration schema.', null],
65 | ['force', 'f', InputOption::VALUE_NONE, 'Force the creation if file already exists.', null],
66 | ];
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Console/RequestCommand.php:
--------------------------------------------------------------------------------
1 | $this->argument('name'),
35 | 'rules' => $this->option('rules'),
36 | 'auth' => $this->option('auth'),
37 | 'scaffold' => $this->option('scaffold'),
38 | 'force' => $this->option('force'),
39 | ]);
40 |
41 | $this->info('Form request created successfully.');
42 | } catch (FileAlreadyExistsException $e) {
43 | $this->comment($e->getMessage());
44 | }
45 | }
46 |
47 | /**
48 | * The array of command arguments.
49 | *
50 | * @return array
51 | */
52 | public function getArguments()
53 | {
54 | return [
55 | ['name', InputArgument::REQUIRED, 'The name of class being generated.', null],
56 | ];
57 | }
58 |
59 | /**
60 | * The array of command options.
61 | *
62 | * @return array
63 | */
64 | public function getOptions()
65 | {
66 | return [
67 | ['rules', 'r', InputOption::VALUE_OPTIONAL, 'The rules.', null],
68 | ['scaffold', 's', InputOption::VALUE_NONE, 'Determine whether the request class generated with scaffold.', null],
69 | ['auth', 'a', InputOption::VALUE_NONE, 'Determine whether the request class needs authorized.', null],
70 | ['force', 'f', InputOption::VALUE_NONE, 'Force the creation if file already exists.', null],
71 | ];
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Console/ScaffoldCommand.php:
--------------------------------------------------------------------------------
1 | run();
32 | }
33 |
34 | /**
35 | * The array of command arguments.
36 | *
37 | * @return array
38 | */
39 | public function getArguments()
40 | {
41 | return [
42 | ['entity', InputArgument::REQUIRED, 'The entity name.', null],
43 | ];
44 | }
45 |
46 | /**
47 | * The array of command options.
48 | *
49 | * @return array
50 | */
51 | public function getOptions()
52 | {
53 | return [
54 | ['fields', null, InputOption::VALUE_OPTIONAL, 'The fields of migration. Separated with comma (,).', null],
55 | ['prefix', null, InputOption::VALUE_OPTIONAL, 'The prefix path & routes.', null],
56 | ['no-question', null, InputOption::VALUE_NONE, 'Don\'t ask any question.', null],
57 | ['existing', 'e', InputOption::VALUE_NONE, 'Generate scaffold from an existing table.', null],
58 | ['force', 'f', InputOption::VALUE_NONE, 'Force the creation if file already exists.', null],
59 | ];
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Console/SeedCommand.php:
--------------------------------------------------------------------------------
1 | $this->argument('name'),
36 | 'master' => $this->option('master'),
37 | 'force' => $this->option('force'),
38 | ]);
39 |
40 | $this->info('Seed created successfully.');
41 |
42 | $composer->dumpAutoloads();
43 | } catch (FileAlreadyExistsException $e) {
44 | $this->comment($e->getMessage());
45 | }
46 | }
47 |
48 | /**
49 | * The array of command arguments.
50 | *
51 | * @return array
52 | */
53 | public function getArguments()
54 | {
55 | return [
56 | ['name', InputArgument::REQUIRED, 'The name of class being generated.', null],
57 | ];
58 | }
59 |
60 | /**
61 | * The array of command options.
62 | *
63 | * @return array
64 | */
65 | public function getOptions()
66 | {
67 | return [
68 | ['master', 'm', InputOption::VALUE_NONE, 'Generate master database seeder.', null],
69 | ['force', 'f', InputOption::VALUE_NONE, 'Force the creation if file already exists.', null],
70 | ];
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Console/ViewCommand.php:
--------------------------------------------------------------------------------
1 | $this->argument('name'),
35 | 'extends' => $this->option('extends'),
36 | 'section' => $this->option('section'),
37 | 'master' => $this->option('master'),
38 | 'plain' => $this->option('plain'),
39 | 'content' => $this->option('content'),
40 | 'template' => $this->option('template'),
41 | 'force' => $this->option('force'),
42 | ]);
43 |
44 | $this->info('View created successfully.');
45 | } catch (FileAlreadyExistsException $e) {
46 | $this->comment($e->getMessage());
47 | }
48 | }
49 |
50 | /**
51 | * The array of command arguments.
52 | *
53 | * @return array
54 | */
55 | public function getArguments()
56 | {
57 | return [
58 | ['name', InputArgument::REQUIRED, 'The name of class being generated.', null],
59 | ];
60 | }
61 |
62 | /**
63 | * The array of command options.
64 | *
65 | * @return array
66 | */
67 | public function getOptions()
68 | {
69 | return [
70 | ['extends', 'e', InputOption::VALUE_OPTIONAL, 'The name of view layout being used.', 'layouts.master'],
71 | ['section', 's', InputOption::VALUE_OPTIONAL, 'The name of section being used.', 'content'],
72 | ['content', 'c', InputOption::VALUE_OPTIONAL, 'The view content.', null],
73 | ['template', 't', InputOption::VALUE_OPTIONAL, 'The path of view template.', null],
74 | ['master', 'm', InputOption::VALUE_NONE, 'Create a master view.', null],
75 | ['plain', 'p', InputOption::VALUE_NONE, 'Create a blank view.', null],
76 | ['force', 'f', InputOption::VALUE_NONE, 'Force the creation if file already exists.', null],
77 | ];
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/ConsoleGenerator.php:
--------------------------------------------------------------------------------
1 | getAppNamespace().'Console\\Commands\\';
32 | }
33 |
34 | /**
35 | * Get template replacements.
36 | *
37 | * @return array
38 | */
39 | public function getReplacements()
40 | {
41 | return array_merge(parent::getReplacements(), [
42 | 'command' => $this->option('command', 'command:name'),
43 | 'description' => $this->option('description', 'Command description'),
44 | ]);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ControllerGenerator.php:
--------------------------------------------------------------------------------
1 | resource) {
22 | $this->stub = 'controller/resource';
23 | } elseif ($this->scaffold) {
24 | $this->stub = 'controller/scaffold';
25 | $this->scaffolder = new ControllerScaffolder($this->getClass(), $this->getPrefix());
26 | }
27 | }
28 |
29 | /**
30 | * Get prefix class.
31 | *
32 | * @return string
33 | */
34 | public function getPrefix()
35 | {
36 | $paths = explode('/', $this->getName());
37 |
38 | array_pop($paths);
39 |
40 | return strtolower(implode('\\', $paths));
41 | }
42 |
43 | /**
44 | * Get base path of destination file.
45 | *
46 | * @return string
47 | */
48 | public function getBasePath()
49 | {
50 | return app_path().'/Http/Controllers';
51 | }
52 |
53 | /**
54 | * Get root namespace.
55 | *
56 | * @return string
57 | */
58 | public function getRootNamespace()
59 | {
60 | return $this->getAppNamespace().'Http\\Controllers\\';
61 | }
62 |
63 | /**
64 | * Get template replacements.
65 | *
66 | * @return array
67 | */
68 | public function getReplacements()
69 | {
70 | $replacements = array_merge(parent::getReplacements(), ['root_namespace' => $this->getAppNamespace()]);
71 |
72 | if ($this->scaffold) {
73 | return array_merge($replacements, $this->scaffolder->toArray());
74 | }
75 |
76 | return $replacements;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/FileAlreadyExistsException.php:
--------------------------------------------------------------------------------
1 | path = $path;
24 | parent::__construct('File already exist at path: '.$path);
25 | }
26 |
27 | /**
28 | * Gets the value of path.
29 | *
30 | * @return mixed
31 | */
32 | public function getPath()
33 | {
34 | return $this->path;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/FormDumpers/FieldsDumper.php:
--------------------------------------------------------------------------------
1 | fields = $fields;
27 | }
28 |
29 | /**
30 | * Get schema parser.
31 | *
32 | * @return string
33 | */
34 | public function getParser()
35 | {
36 | return new SchemaParser($this->fields);
37 | }
38 |
39 | /**
40 | * Render the form.
41 | *
42 | * @return string
43 | */
44 | public function render()
45 | {
46 | $results = '';
47 |
48 | foreach ($this->getParser()->toArray() as $name => $types) {
49 | $results .= $this->getStub($this->getFieldType($types), $name).PHP_EOL;
50 | }
51 |
52 | return $results;
53 | }
54 |
55 | /**
56 | * Convert the fields to html heading.
57 | *
58 | * @return string
59 | */
60 | public function toHeading()
61 | {
62 | $results = '';
63 |
64 | foreach ($this->getParser()->toArray() as $name => $types) {
65 | if (in_array($name, $this->ignores)) {
66 | continue;
67 | }
68 |
69 | $results .= "\t\t\t".'
'.ucwords($name).' | '.PHP_EOL;
70 | }
71 |
72 | return $results;
73 | }
74 |
75 | /**
76 | * Convert the fields to formatted php script.
77 | *
78 | * @param string $var
79 | *
80 | * @return string
81 | */
82 | public function toBody($var)
83 | {
84 | $results = '';
85 |
86 | foreach ($this->getParser()->toArray() as $name => $types) {
87 | if (in_array($name, $this->ignores)) {
88 | continue;
89 | }
90 |
91 | $results .= "\t\t\t\t\t".'{!! $'.$var.'->'.$name.' !!} | '.PHP_EOL;
92 | }
93 |
94 | return $results;
95 | }
96 |
97 | /**
98 | * Get replacements for $SHOW_BODY$.
99 | *
100 | * @param string $var
101 | *
102 | * @return string
103 | */
104 | public function toRows($var)
105 | {
106 | $results = PHP_EOL;
107 |
108 | foreach ($this->getParser()->toArray() as $name => $types) {
109 | if (in_array($name, $this->ignores)) {
110 | continue;
111 | }
112 |
113 | $results .= Stub::create('/scaffold/row.stub', [
114 | 'label' => ucwords($name),
115 | 'column' => $name,
116 | 'var' => $var,
117 | ])->render();
118 | }
119 |
120 | return $results.PHP_EOL;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/FormDumpers/StubTrait.php:
--------------------------------------------------------------------------------
1 | 'text',
16 | 'text' => 'textarea',
17 | 'boolean' => 'checkbox',
18 | ];
19 |
20 | /**
21 | * The supported inputs.
22 | *
23 | * @var array
24 | */
25 | protected $inputs = [
26 | 'text',
27 | 'textarea',
28 | 'checkbox',
29 | 'select',
30 | 'radio',
31 | 'password',
32 | ];
33 |
34 | /**
35 | * The array of special input/type.
36 | *
37 | * @var array
38 | */
39 | protected $specials = [
40 | 'email',
41 | 'password',
42 | ];
43 |
44 | /**
45 | * The array of ignores columns.
46 | *
47 | * @var array
48 | */
49 | protected $ignores = [
50 | 'id',
51 | 'remember_token',
52 | 'deleted_at',
53 | 'created_at',
54 | 'updated_at',
55 | ];
56 |
57 | /**
58 | * Get stub template.
59 | *
60 | * @param string $type
61 | * @param string $name
62 | *
63 | * @return string
64 | */
65 | public function getStub($type, $name)
66 | {
67 | if (in_array($name, $this->ignores)) {
68 | return;
69 | }
70 |
71 | $type = $this->getInputType($type, $name);
72 |
73 | return Stub::create('/form/'.$type.'.stub', [
74 | 'name' => $name,
75 | 'label' => ucwords(str_replace('_', ' ', $name)),
76 | ])->render();
77 | }
78 |
79 | /**
80 | * Get input type.
81 | *
82 | * @param string $type
83 | * @param string $name
84 | *
85 | * @return string
86 | */
87 | public function getInputType($type, $name)
88 | {
89 | if (in_array($name, $this->specials)) {
90 | return $name;
91 | }
92 |
93 | if (array_key_exists($type, $this->types)) {
94 | return $this->types[$type];
95 | }
96 |
97 | return in_array($type, $this->inputs) ? $type : 'text';
98 | }
99 |
100 | /**
101 | * Get field type.
102 | *
103 | * @param array $types
104 | *
105 | * @return string
106 | */
107 | public function getFieldType($types)
108 | {
109 | return array_first($types, function ($key, $value) {
110 | return $value;
111 | });
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/FormDumpers/TableDumper.php:
--------------------------------------------------------------------------------
1 | table = $table;
34 | }
35 |
36 | /**
37 | * Make a new instance of this class.
38 | *
39 | * @param string $table
40 | * @return self
41 | */
42 | public static function make($table)
43 | {
44 | return new static($table);
45 | }
46 |
47 | /**
48 | * Set excepted fields.
49 | *
50 | * @param array|string $except
51 | * @return self
52 | */
53 | public function except($except)
54 | {
55 | $this->except = $except;
56 |
57 | return $this;
58 | }
59 |
60 | /**
61 | * Get table name.
62 | *
63 | * @return string
64 | */
65 | public function getTable()
66 | {
67 | return $this->table;
68 | }
69 |
70 | /**
71 | * Get column.
72 | *
73 | * @return string
74 | */
75 | public function getColumns()
76 | {
77 | return DB::getDoctrineSchemaManager()->listTableDetails($this->getTable())->getColumns();
78 | }
79 |
80 | /**
81 | * Convert table description to migration schema.
82 | *
83 | * @return string
84 | */
85 | public function toSchema()
86 | {
87 | $schema = [];
88 |
89 | foreach ($this->getColumns() as $column) {
90 | if (! in_array($name = $column->getName(), $this->except)) {
91 | $schema[] = $name.':'.strtolower($column->getType());
92 | }
93 | }
94 |
95 | return implode(', ', $schema);
96 | }
97 |
98 | /**
99 | * Render the form.
100 | *
101 | * @return string
102 | */
103 | public function render()
104 | {
105 | $columns = $this->getColumns();
106 |
107 | $results = '';
108 |
109 | foreach ($columns as $column) {
110 | $results .= $this->getStub($column->getType()->getName(), $column->getName());
111 | }
112 |
113 | return $results;
114 | }
115 |
116 | /**
117 | * Convert the fields to html heading.
118 | *
119 | * @return string
120 | */
121 | public function toHeading()
122 | {
123 | $results = '';
124 |
125 | foreach ($this->getColumns() as $column) {
126 | if (in_array($name = $column->getName(), $this->ignores)) {
127 | continue;
128 | }
129 |
130 | $results .= "\t\t\t".''.ucwords($name).' | '.PHP_EOL;
131 | }
132 |
133 | return $results;
134 | }
135 |
136 | /**
137 | * Convert the fields to formatted php script.
138 | *
139 | * @param string $var
140 | *
141 | * @return string
142 | */
143 | public function toBody($var)
144 | {
145 | $results = '';
146 |
147 | foreach ($this->getColumns() as $column) {
148 | if (in_array($name = $column->getName(), $this->ignores)) {
149 | continue;
150 | }
151 |
152 | $results .= "\t\t\t\t\t".'{!! $'.$var.'->'.$name.' !!} | '.PHP_EOL;
153 | }
154 |
155 | return $results;
156 | }
157 |
158 | /**
159 | * Get replacements for $SHOW_BODY$.
160 | *
161 | * @param string $var
162 | *
163 | * @return string
164 | */
165 | public function toRows($var)
166 | {
167 | $results = PHP_EOL;
168 |
169 | foreach ($this->getColumns() as $column) {
170 | if (in_array($name = $column->getName(), $this->ignores)) {
171 | continue;
172 | }
173 |
174 | $results .= Stub::create('scaffold/row.stub', [
175 | 'label' => ucwords($name),
176 | 'column' => $name,
177 | 'var' => $var,
178 | ])->render();
179 | }
180 |
181 | return $results.PHP_EOL;
182 | }
183 | }
184 |
--------------------------------------------------------------------------------
/FormGenerator.php:
--------------------------------------------------------------------------------
1 | name = $name;
33 | $this->fields = $fields;
34 | }
35 |
36 | /**
37 | * Render the form.
38 | *
39 | * @return string
40 | */
41 | public function render()
42 | {
43 | if ($this->fields) {
44 | return $this->renderFromFields();
45 | }
46 |
47 | return $this->renderFromDb();
48 | }
49 |
50 | /**
51 | * Render form from database.
52 | *
53 | * @return string
54 | */
55 | public function renderFromDb()
56 | {
57 | return (new TableDumper($this->name))->render();
58 | }
59 |
60 | /**
61 | * Render form from fields option.
62 | *
63 | * @return string
64 | */
65 | public function renderFromFields()
66 | {
67 | return (new FieldsDumper($this->fields))->render();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Generator.php:
--------------------------------------------------------------------------------
1 | filesystem = new Filesystem();
42 | $this->options = $options;
43 | }
44 |
45 | /**
46 | * Quick run via static-method.
47 | *
48 | * @param array $options
49 | * @return mixed
50 | */
51 | public static function generate(array $options = [])
52 | {
53 | return (new static($options))->run();
54 | }
55 |
56 | /**
57 | * Get the filesystem instance.
58 | *
59 | * @return \Illuminate\Filesystem\Filesystem
60 | */
61 | public function getFilesystem()
62 | {
63 | return $this->filesystem;
64 | }
65 |
66 | /**
67 | * Set the filesystem instance.
68 | *
69 | * @param \Illuminate\Filesystem\Filesystem $filesystem
70 | *
71 | * @return $this
72 | */
73 | public function setFilesystem(Filesystem $filesystem)
74 | {
75 | $this->filesystem = $filesystem;
76 |
77 | return $this;
78 | }
79 |
80 | /**
81 | * Get stub template for generated file.
82 | *
83 | * @return string
84 | */
85 | public function getStub()
86 | {
87 | $stub = new Stub($this->stub.'.stub', $this->getReplacements());
88 |
89 | return $stub->render();
90 | }
91 |
92 | /**
93 | * Get template replacements.
94 | *
95 | * @return array
96 | */
97 | public function getReplacements()
98 | {
99 | return [
100 | 'class' => $this->getClass(),
101 | 'namespace' => $this->getNamespace(),
102 | 'root_namespace' => $this->getRootNamespace(),
103 | ];
104 | }
105 |
106 | /**
107 | * Get base path of destination file.
108 | *
109 | * @return string
110 | */
111 | public function getBasePath()
112 | {
113 | return base_path();
114 | }
115 |
116 | /**
117 | * Get destination path for generated file.
118 | *
119 | * @return string
120 | */
121 | public function getPath()
122 | {
123 | return $this->getBasePath().'/'.$this->getName().'.php';
124 | }
125 |
126 | /**
127 | * Get name input.
128 | *
129 | * @return string
130 | */
131 | public function getName()
132 | {
133 | $name = $this->name;
134 |
135 | if (str_contains($this->name, '\\')) {
136 | $name = str_replace('\\', '/', $this->name);
137 | }
138 |
139 | if (str_contains($this->name, '/')) {
140 | $name = str_replace('/', '/', $this->name);
141 | }
142 |
143 | return Str::studly(str_replace(' ', '/', ucwords(str_replace('/', ' ', $name))));
144 | }
145 |
146 | /**
147 | * Get class name.
148 | *
149 | * @return string
150 | */
151 | public function getClass()
152 | {
153 | return Str::studly(class_basename($this->getName()));
154 | }
155 |
156 | /**
157 | * Get paths of namespace.
158 | *
159 | * @return array
160 | */
161 | public function getSegments()
162 | {
163 | return explode('/', $this->getName());
164 | }
165 |
166 | /**
167 | * Get root namespace.
168 | *
169 | * @return string
170 | */
171 | public function getRootNamespace()
172 | {
173 | return $this->getAppNamespace();
174 | }
175 |
176 | /**
177 | * Get class namespace.
178 | *
179 | * @return string
180 | */
181 | public function getNamespace()
182 | {
183 | $segments = $this->getSegments();
184 |
185 | array_pop($segments);
186 |
187 | $rootNamespace = $this->getRootNamespace();
188 |
189 | if ($rootNamespace == false) {
190 | return;
191 | }
192 |
193 | return 'namespace '.rtrim($rootNamespace.implode($segments, '\\'), '\\').';';
194 | }
195 |
196 | /**
197 | * Setup some hook.
198 | */
199 | public function setUp()
200 | {
201 | //
202 | }
203 |
204 | /**
205 | * Run the generator.
206 | *
207 | * @return int
208 | *
209 | * @throws FileAlreadyExistsException
210 | */
211 | public function run()
212 | {
213 | $this->setUp();
214 |
215 | if ($this->filesystem->exists($path = $this->getPath()) && !$this->force) {
216 | throw new FileAlreadyExistsException($path);
217 | }
218 |
219 | if (!$this->filesystem->isDirectory($dir = dirname($path))) {
220 | $this->filesystem->makeDirectory($dir, 0777, true, true);
221 | }
222 |
223 | return $this->filesystem->put($path, $this->getStub());
224 | }
225 |
226 | /**
227 | * Get options.
228 | *
229 | * @return string
230 | */
231 | public function getOptions()
232 | {
233 | return $this->options;
234 | }
235 |
236 | /**
237 | * Determinte whether the given key exist in options array.
238 | *
239 | * @param string $key
240 | *
241 | * @return bool
242 | */
243 | public function hasOption($key)
244 | {
245 | return array_key_exists($key, $this->options);
246 | }
247 |
248 | /**
249 | * Get value from options by given key.
250 | *
251 | * @param string $key
252 | * @param string|null $default
253 | *
254 | * @return string
255 | */
256 | public function getOption($key, $default = null)
257 | {
258 | if (!$this->hasOption($key)) {
259 | return $default;
260 | }
261 |
262 | return $this->options[$key] ?: $default;
263 | }
264 |
265 | /**
266 | * Helper method for "getOption".
267 | *
268 | * @param string $key
269 | * @param string|null $default
270 | *
271 | * @return string
272 | */
273 | public function option($key, $default = null)
274 | {
275 | return $this->getOption($key, $default);
276 | }
277 |
278 | /**
279 | * Handle call to __get method.
280 | *
281 | * @param string $key
282 | *
283 | * @return string|mixed
284 | */
285 | public function __get($key)
286 | {
287 | if (property_exists($this, $key)) {
288 | return $this->{$key};
289 | }
290 |
291 | return $this->option($key);
292 | }
293 | }
294 |
--------------------------------------------------------------------------------
/GeneratorsServiceProvider.php:
--------------------------------------------------------------------------------
1 | publishes([
41 | __DIR__ . '/Stubs/' => $templatePath
42 | ], 'stubs');
43 |
44 | $configPath = config_path('generators.php');
45 |
46 | $this->publishes([
47 | __DIR__.'/config.php' => $configPath,
48 | ], 'config');
49 |
50 | if (file_exists($configPath)) {
51 | $this->mergeConfigFrom($configPath, 'generators');
52 | }
53 |
54 | $this->setStubBasePath($templatePath);
55 | }
56 |
57 | /**
58 | * Set stub base path.
59 | *
60 | * @param string $templatePath
61 | * @return void
62 | */
63 | protected function setStubBasePath($templatePath)
64 | {
65 | Stub::setBasePath($templatePath);
66 | }
67 |
68 | /**
69 | * Register the service provider.
70 | */
71 | public function register()
72 | {
73 | foreach ($this->consoles as $console) {
74 | $this->commands('Pingpong\Generators\Console\\'.$console.'Command');
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Pingpong Labs
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | * Neither the name of generators nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 |
--------------------------------------------------------------------------------
/MigrationGenerator.php:
--------------------------------------------------------------------------------
1 | getBasePath().$this->getFileName().'.php';
36 | }
37 |
38 | /**
39 | * Get root namespace.
40 | *
41 | * @return string
42 | */
43 | public function getRootNamespace()
44 | {
45 | return '';
46 | }
47 |
48 | /**
49 | * Get migration name.
50 | *
51 | * @return string
52 | */
53 | public function getMigrationName()
54 | {
55 | if ($this->existing) {
56 | return 'create_'.str_plural($this->name).'_table';
57 | }
58 |
59 | return strtolower($this->name);
60 | }
61 |
62 | /**
63 | * Get file name.
64 | *
65 | * @return string
66 | */
67 | public function getFileName()
68 | {
69 | return date('Y_m_d_His_').$this->getMigrationName();
70 | }
71 |
72 | /**
73 | * Get schema parser.
74 | *
75 | * @return SchemaParser
76 | */
77 | public function getSchemaParser()
78 | {
79 | return new SchemaParser($this->fields);
80 | }
81 |
82 | /**
83 | * Get name parser.
84 | *
85 | * @return NameParser
86 | */
87 | public function getNameParser()
88 | {
89 | return new NameParser($this->name);
90 | }
91 |
92 | /**
93 | * Get stub templates.
94 | *
95 | * @return string
96 | */
97 | public function getStub()
98 | {
99 | $parser = $this->getNameParser();
100 |
101 | if ($this->existing) {
102 | $this->name = 'create_'.str_plural($this->name).'_table';
103 |
104 | $parser = $this->getNameParser();
105 |
106 | $fields = (new TableDumper($parser->getTable()))->toSchema();
107 |
108 | $stub = Stub::create('/migration/create.stub', [
109 | 'class' => $this->getClass(),
110 | 'table' => $parser->getTable(),
111 | 'fields' => (new SchemaParser($fields))->render(),
112 | ]);
113 | }
114 | elseif ($parser->isCreate()) {
115 | $stub = Stub::create('/migration/create.stub', [
116 | 'class' => $this->getClass(),
117 | 'table' => $parser->getTable(),
118 | 'fields' => $this->getSchemaParser()->render(),
119 | ]);
120 | } elseif ($parser->isAdd()) {
121 | $stub = Stub::create('/migration/add.stub', [
122 | 'class' => $this->getClass(),
123 | 'table' => $parser->getTable(),
124 | 'fields_up' => $this->getSchemaParser()->up(),
125 | 'fields_down' => $this->getSchemaParser()->down(),
126 | ]);
127 | } elseif ($parser->isDelete()) {
128 | $stub = Stub::create('/migration/delete.stub', [
129 | 'class' => $this->getClass(),
130 | 'table' => $parser->getTable(),
131 | 'fields_down' => $this->getSchemaParser()->up(),
132 | 'fields_up' => $this->getSchemaParser()->down(),
133 | ]);
134 | } elseif ($parser->isDrop()) {
135 | $stub = Stub::create('/migration/drop.stub', [
136 | 'class' => $this->getClass(),
137 | 'table' => $parser->getTable(),
138 | 'fields' => $this->getSchemaParser()->render(),
139 | ]);
140 | } else {
141 | $stub = false;
142 | }
143 |
144 | if ($stub) {
145 | return $stub->render();
146 | }
147 |
148 | return parent::getStub();
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/Migrations/NameParser.php:
--------------------------------------------------------------------------------
1 | [
28 | 'create',
29 | 'make',
30 | ],
31 | 'delete' => [
32 | 'delete',
33 | 'remove',
34 | ],
35 | 'add' => [
36 | 'add',
37 | 'update',
38 | 'append',
39 | 'insert',
40 | ],
41 | 'drop' => [
42 | 'destroy',
43 | 'drop',
44 | ],
45 | ];
46 |
47 | /**
48 | * The constructor.
49 | *
50 | * @param string $name
51 | */
52 | public function __construct($name)
53 | {
54 | $this->name = $name;
55 | $this->data = $this->fetchData();
56 | }
57 |
58 | /**
59 | * Get original migration name.
60 | *
61 | * @return string
62 | */
63 | public function getOriginalName()
64 | {
65 | return $this->name;
66 | }
67 |
68 | /**
69 | * Get schema type or action.
70 | *
71 | * @return string
72 | */
73 | public function getAction()
74 | {
75 | return head($this->data);
76 | }
77 |
78 | /**
79 | * Get table name.
80 | *
81 | * @return string
82 | */
83 | public function getTable()
84 | {
85 | return $this->getTableName();
86 | }
87 |
88 | /**
89 | * Get the table will be used.
90 | *
91 | * @return string
92 | */
93 | public function getTableName()
94 | {
95 | $matches = array_reverse($this->getMatches());
96 |
97 | return array_shift($matches);
98 | }
99 |
100 | /**
101 | * Get matches data from regex.
102 | *
103 | * @return array
104 | */
105 | public function getMatches()
106 | {
107 | preg_match($this->getPattern(), $this->name, $matches);
108 |
109 | return $matches;
110 | }
111 |
112 | /**
113 | * Get name pattern.
114 | *
115 | * @return string
116 | */
117 | public function getPattern()
118 | {
119 | switch ($action = $this->getAction()) {
120 | case 'add':
121 | case 'append':
122 | case 'update':
123 | case 'insert':
124 | return "/{$action}_(.*)_to_(.*)_table/";
125 | break;
126 |
127 | case 'delete':
128 | case 'remove':
129 | case 'alter':
130 | return "/{$action}_(.*)_from_(.*)_table/";
131 | break;
132 |
133 | default:
134 | return "/{$action}_(.*)_table/";
135 | break;
136 | }
137 | }
138 |
139 | /**
140 | * Fetch the migration name to an array data.
141 | *
142 | * @return array
143 | */
144 | protected function fetchData()
145 | {
146 | return explode('_', $this->name);
147 | }
148 |
149 | /**
150 | * Get the array data.
151 | *
152 | * @return array
153 | */
154 | public function getData()
155 | {
156 | return $this->data;
157 | }
158 |
159 | /**
160 | * Determine whether the given type is same with the current schema action or type.
161 | *
162 | * @param $type
163 | *
164 | * @return bool
165 | */
166 | public function is($type)
167 | {
168 | return $type == $this->getAction();
169 | }
170 |
171 | /**
172 | * Determine whether the current schema action is a adding action.
173 | *
174 | * @return bool
175 | */
176 | public function isAdd()
177 | {
178 | return in_array($this->getAction(), $this->actions['add']);
179 | }
180 |
181 | /**
182 | * Determine whether the current schema action is a deleting action.
183 | *
184 | * @return bool
185 | */
186 | public function isDelete()
187 | {
188 | return in_array($this->getAction(), $this->actions['delete']);
189 | }
190 |
191 | /**
192 | * Determine whether the current schema action is a creating action.
193 | *
194 | * @return bool
195 | */
196 | public function isCreate()
197 | {
198 | return in_array($this->getAction(), $this->actions['create']);
199 | }
200 |
201 | /**
202 | * Determine whether the current schema action is a dropping action.
203 | *
204 | * @return bool
205 | */
206 | public function isDrop()
207 | {
208 | return in_array($this->getAction(), $this->actions['drop']);
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/Migrations/SchemaParser.php:
--------------------------------------------------------------------------------
1 | 'rememberToken()',
16 | 'soft_delete' => 'softDeletes()',
17 | ];
18 |
19 | /**
20 | * The migration schema.
21 | *
22 | * @var string
23 | */
24 | protected $schema;
25 |
26 | /**
27 | * The relationship keys.
28 | *
29 | * @var array
30 | */
31 | protected $relationshipKeys = [
32 | 'belongsTo',
33 | ];
34 |
35 | /**
36 | * Create new instance.
37 | *
38 | * @param string|null $schema
39 | */
40 | public function __construct($schema = null)
41 | {
42 | $this->schema = $schema;
43 | }
44 |
45 | /**
46 | * Parse a string to array of formatted schema.
47 | *
48 | * @param string $schema
49 | *
50 | * @return array
51 | */
52 | public function parse($schema)
53 | {
54 | $this->schema = $schema;
55 |
56 | $parsed = [];
57 |
58 | foreach ($this->getSchemas() as $schemaArray) {
59 | $column = $this->getColumn($schemaArray);
60 |
61 | $attributes = $this->getAttributes($column, $schemaArray);
62 |
63 | $parsed[$column] = $attributes;
64 | }
65 |
66 | return $parsed;
67 | }
68 |
69 | /**
70 | * Get array of schema.
71 | *
72 | * @return array
73 | */
74 | public function getSchemas()
75 | {
76 | if (is_null($this->schema)) {
77 | return [];
78 | }
79 |
80 | return explode(',', str_replace(' ', '', $this->schema));
81 | }
82 |
83 | /**
84 | * Convert string migration to array.
85 | *
86 | * @return array
87 | */
88 | public function toArray()
89 | {
90 | return $this->parse($this->schema);
91 | }
92 |
93 | /**
94 | * Render the migration to formatted script.
95 | *
96 | * @return string
97 | */
98 | public function render()
99 | {
100 | $results = '';
101 |
102 | foreach ($this->toArray() as $column => $attributes) {
103 | $results .= $this->createField($column, $attributes);
104 | }
105 |
106 | return $results;
107 | }
108 |
109 | /**
110 | * Render up migration fields.
111 | *
112 | * @return string
113 | */
114 | public function up()
115 | {
116 | return $this->render();
117 | }
118 |
119 | /**
120 | * Render down migration fields.
121 | *
122 | * @return string
123 | */
124 | public function down()
125 | {
126 | $results = '';
127 |
128 | foreach ($this->toArray() as $column => $attributes) {
129 | $attributes = [head($attributes)];
130 | $results .= $this->createField($column, $attributes, 'remove');
131 | }
132 |
133 | return $results;
134 | }
135 |
136 | /**
137 | * Create field.
138 | *
139 | * @param string $column
140 | * @param array $attributes
141 | *
142 | * @return string
143 | */
144 | public function createField($column, $attributes, $type = 'add')
145 | {
146 | $results = "\t\t\t".'$table';
147 |
148 | foreach ($attributes as $key => $field) {
149 | if (in_array($column, $this->relationshipKeys)) {
150 | $results .= $this->addRelationColumn($key, $field, $column);
151 | } else {
152 | $results .= $this->{"{$type}Column"}($key, $field, $column);
153 | }
154 | }
155 |
156 | return $results .= ';'.PHP_EOL;
157 | }
158 |
159 | /**
160 | * Add relation column.
161 | *
162 | * @param int $key
163 | * @param string $field
164 | * @param string $column
165 | *
166 | * @return string
167 | */
168 | protected function addRelationColumn($key, $field, $column)
169 | {
170 | $relatedColumn = snake_case(class_basename($field)).'_id';
171 |
172 | $method = 'integer';
173 |
174 | return "->{$method}('{$relatedColumn}')";
175 | }
176 |
177 | /**
178 | * Format field to script.
179 | *
180 | * @param int $key
181 | * @param string $field
182 | * @param string $column
183 | *
184 | * @return string
185 | */
186 | protected function addColumn($key, $field, $column)
187 | {
188 | if ($this->hasCustomAttribute($column)) {
189 | return '->'.$field;
190 | }
191 |
192 | if ($key == 0) {
193 | return '->'.$field."('".$column."')";
194 | }
195 |
196 | if (str_contains($field, '(')) {
197 | return '->'.$field;
198 | }
199 |
200 | return '->'.$field.'()';
201 | }
202 |
203 | /**
204 | * Format field to script.
205 | *
206 | * @param int $key
207 | * @param string $field
208 | * @param string $column
209 | *
210 | * @return string
211 | */
212 | protected function removeColumn($key, $field, $column)
213 | {
214 | if ($this->hasCustomAttribute($column)) {
215 | return '->'.$field;
216 | }
217 |
218 | return '->dropColumn('."'".$column."')";
219 | }
220 |
221 | /**
222 | * Get column name from schema.
223 | *
224 | * @param string $schema
225 | *
226 | * @return string
227 | */
228 | public function getColumn($schema)
229 | {
230 | return array_first(explode(':', $schema), function ($key, $value) {
231 | return $value;
232 | });
233 | }
234 |
235 | /**
236 | * Get column attributes.
237 | *
238 | * @param string $column
239 | * @param string $schema
240 | *
241 | * @return array
242 | */
243 | public function getAttributes($column, $schema)
244 | {
245 | $fields = str_replace($column.':', '', $schema);
246 |
247 | return $this->hasCustomAttribute($column) ? $this->getCustomAttribute($column) : explode(':', $fields);
248 | }
249 |
250 | /**
251 | * Determinte whether the given column is exist in customAttributes array.
252 | *
253 | * @param string $column
254 | *
255 | * @return bool
256 | */
257 | public function hasCustomAttribute($column)
258 | {
259 | return array_key_exists($column, $this->customAttributes);
260 | }
261 |
262 | /**
263 | * Get custom attributes value.
264 | *
265 | * @param string $column
266 | *
267 | * @return array
268 | */
269 | public function getCustomAttribute($column)
270 | {
271 | return (array) $this->customAttributes[$column];
272 | }
273 | }
274 |
--------------------------------------------------------------------------------
/ModelGenerator.php:
--------------------------------------------------------------------------------
1 | getBasePath().'/'.$this->getName().'.php';
34 | }
35 |
36 | /**
37 | * Get array replacements.
38 | *
39 | * @return array
40 | */
41 | public function getReplacements()
42 | {
43 | return array_merge(parent::getReplacements(), [
44 | 'fillable' => $this->getFillable(),
45 | ]);
46 | }
47 |
48 | /**
49 | * Get schema parser.
50 | *
51 | * @return SchemaParser
52 | */
53 | public function getSchemaParser()
54 | {
55 | return new SchemaParser($this->fillable);
56 | }
57 |
58 | /**
59 | * Get the fillable attributes.
60 | *
61 | * @return string
62 | */
63 | public function getFillable()
64 | {
65 | if (!$this->fillable) {
66 | return '[]';
67 | }
68 |
69 | $results = '['.PHP_EOL;
70 |
71 | foreach ($this->getSchemaParser()->toArray() as $column => $value) {
72 | $results .= "\t\t'{$column}',".PHP_EOL;
73 | }
74 |
75 | return $results."\t".']';
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/PivotGenerator.php:
--------------------------------------------------------------------------------
1 | getBasePath().$this->getFilename().'.php';
34 | }
35 |
36 | /**
37 | * Get filename.
38 | *
39 | * @return string
40 | */
41 | public function getFilename()
42 | {
43 | return date('Y_m_d_His_').$this->getMigrationName();
44 | }
45 |
46 | /**
47 | * Get migration name.
48 | *
49 | * @return string
50 | */
51 | public function getMigrationName()
52 | {
53 | return 'create_'.$this->getPivotTableName().'_pivot_table';
54 | }
55 |
56 | /**
57 | * Get class name.
58 | *
59 | * @return string
60 | */
61 | public function getClass()
62 | {
63 | return Str::studly($this->getMigrationName());
64 | }
65 |
66 | /**
67 | * Get the name of the pivot table.
68 | *
69 | * @return string
70 | */
71 | public function getPivotTableName()
72 | {
73 | return implode('_', array_map('str_singular', $this->getSortedTableNames()));
74 | }
75 |
76 | /**
77 | * Get sorted table names.
78 | *
79 | * @return array
80 | */
81 | public function getSortedTableNames()
82 | {
83 | $tables = [
84 | strtolower($this->table_one),
85 | strtolower($this->table_two),
86 | ];
87 |
88 | sort($tables);
89 |
90 | return $tables;
91 | }
92 |
93 | /**
94 | * Get stub replacements.
95 | *
96 | * @return array
97 | */
98 | public function getReplacements()
99 | {
100 | return array_merge(parent::getReplacements(), [
101 | 'table_one' => $this->table_one,
102 | 'table_two' => $this->table_two,
103 | 'column_one' => $this->getColumnOne(),
104 | 'column_two' => $this->getColumnTwo(),
105 | 'table_pivot' => $this->getPivotTableName(),
106 | 'timestamp' => $this->getTimestampReplacement(),
107 | ]);
108 | }
109 |
110 | /**
111 | * Get replacement for TIMESTAMP.
112 | *
113 | * @return string|null
114 | */
115 | public function getTimestampReplacement()
116 | {
117 | if ($this->timestamp) {
118 | return '$table->timestamps();';
119 | }
120 |
121 | return;
122 | }
123 |
124 | /**
125 | * Get column one.
126 | *
127 | * @return string
128 | */
129 | public function getColumnOne()
130 | {
131 | return str_singular($this->table_one);
132 | }
133 |
134 | /**
135 | * Get column two.
136 | *
137 | * @return string
138 | */
139 | public function getColumnTwo()
140 | {
141 | return str_singular($this->table_two);
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Laravel 5 Generators
2 | ==============
3 |
4 | Document : https://github.com/pingpong-labs/docs/blob/2.2/generators.md
5 |
--------------------------------------------------------------------------------
/RequestGenerator.php:
--------------------------------------------------------------------------------
1 | getBasePath().$this->getName().'.php';
34 | }
35 |
36 | /**
37 | * Get root namespace.
38 | *
39 | * @return string
40 | */
41 | public function getRootNamespace()
42 | {
43 | return $this->getAppNamespace().'Http\Requests\\';
44 | }
45 |
46 | /**
47 | * Get stub replacements.
48 | *
49 | * @return array
50 | */
51 | public function getReplacements()
52 | {
53 | return array_merge(parent::getReplacements(), [
54 | 'auth' => $this->getAuth(),
55 | 'rules' => $this->getRules(),
56 | ]);
57 | }
58 |
59 | /**
60 | * Get auth replacement.
61 | *
62 | * @return string
63 | */
64 | public function getAuth()
65 | {
66 | $authorize = $this->auth ? 'true' : 'false';
67 |
68 | return 'return '.$authorize.';';
69 | }
70 |
71 | /**
72 | * Get replacement for "$RULES$".
73 | *
74 | * @return string
75 | */
76 | public function getRules()
77 | {
78 | if (!$this->rules) {
79 | return 'return [];';
80 | }
81 |
82 | $parser = new SchemaParser($this->rules);
83 |
84 | $results = 'return ['.PHP_EOL;
85 |
86 | foreach ($parser->toArray() as $field => $rules) {
87 | $results .= $this->createRules($field, $rules);
88 | }
89 |
90 | $results .= "\t\t];";
91 |
92 | return $results;
93 | }
94 |
95 | /**
96 | * Create a rule.
97 | *
98 | * @param string $field
99 | * @param string $rules
100 | *
101 | * @return string
102 | */
103 | protected function createRules($field, $rules)
104 | {
105 | $rule = str_replace(['(', ')', ';'], [':', '', ','], implode('|', $rules));
106 |
107 | if ($this->scaffold) {
108 | $rule = 'required';
109 | }
110 |
111 | return "\t\t\t'{$field}' => '".$rule."',".PHP_EOL;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/ScaffoldGenerator.php:
--------------------------------------------------------------------------------
1 | console = $console;
49 | $this->laravel = $console->getLaravel();
50 | }
51 |
52 | /**
53 | * Get entity name.
54 | *
55 | * @return string
56 | */
57 | public function getEntity()
58 | {
59 | return strtolower(str_singular($this->console->argument('entity')));
60 | }
61 |
62 | /**
63 | * Get entities name.
64 | *
65 | * @return string
66 | */
67 | public function getEntities()
68 | {
69 | return str_plural($this->getEntity());
70 | }
71 |
72 | /**
73 | * Determine whether the creation is from an existing table.
74 | *
75 | * @return boolen
76 | */
77 | public function existing()
78 | {
79 | return $this->console->option('existing');
80 | }
81 |
82 | /**
83 | * Get schema fields.
84 | *
85 | * @return string
86 | */
87 | public function getFields()
88 | {
89 | if ($this->existing()) {
90 | return TableDumper::make($this->getEntities())->toSchema();
91 | }
92 |
93 | return $this->console->option('fields');
94 | }
95 |
96 | /**
97 | * Get controller name.
98 | *
99 | * @return string
100 | */
101 | public function getControllerName()
102 | {
103 | $controller = Str::studly($this->getEntities()).'Controller';
104 |
105 | if ($this->console->option('prefix')) {
106 | $controller = Str::studly($this->getPrefix('/')).$controller;
107 | }
108 |
109 | return str_replace('/', '\\', $controller);
110 | }
111 |
112 | /**
113 | * Confirm a question with the user.
114 | *
115 | * @param string $message
116 | *
117 | * @return string
118 | */
119 | public function confirm($message)
120 | {
121 | if ($this->console->option('no-question')) {
122 | return true;
123 | }
124 |
125 | return $this->console->confirm($message);
126 | }
127 |
128 | /**
129 | * Generate model.
130 | */
131 | public function generateModel()
132 | {
133 | if (!$this->confirm('Do you want to create a model?')) {
134 | return;
135 | }
136 |
137 | $this->console->call('generate:model', [
138 | 'name' => $this->getEntity(),
139 | '--fillable' => $this->getFields(),
140 | '--force' => $this->console->option('force'),
141 | ]);
142 | }
143 |
144 | /**
145 | * Generate seed.
146 | */
147 | public function generateSeed()
148 | {
149 | if (!$this->confirm('Do you want to create a database seeder class?')) {
150 | return;
151 | }
152 |
153 | $this->console->call('generate:seed', [
154 | 'name' => $this->getEntities(),
155 | '--force' => $this->console->option('force'),
156 | ]);
157 | }
158 |
159 | /**
160 | * Generate migration.
161 | */
162 | public function generateMigration()
163 | {
164 | if (!$this->confirm('Do you want to create a migration?')) {
165 | return;
166 | }
167 |
168 | $existing = $this->existing();
169 | $table = $this->getEntities();
170 |
171 | $this->console->call('generate:migration', [
172 | 'name' => $existing ? $table : "create_{$table}_table",
173 | '--fields' => $this->console->option('fields'),
174 | '--force' => $this->console->option('force'),
175 | '--existing' => $existing,
176 | ]);
177 | }
178 |
179 | /**
180 | * Generate controller.
181 | */
182 | public function generateController()
183 | {
184 | if (!$this->confirm('Do you want to generate a controller?')) {
185 | return;
186 | }
187 |
188 | $this->console->call('generate:controller', [
189 | 'name' => $this->getControllerName(),
190 | '--force' => $this->console->option('force'),
191 | '--scaffold' => true,
192 | ]);
193 | }
194 |
195 | /**
196 | * Get view layout.
197 | *
198 | * @return string
199 | */
200 | public function getViewLayout()
201 | {
202 | return $this->getPrefix('/').'layouts/master';
203 | }
204 |
205 | /**
206 | * Generate a view layout.
207 | */
208 | public function generateViewLayout()
209 | {
210 | if ($this->confirm('Do you want to create master view?')) {
211 | $this->console->call('generate:view', [
212 | 'name' => $this->getViewLayout(),
213 | '--master' => true,
214 | '--force' => $this->console->option('force'),
215 | ]);
216 | }
217 | }
218 |
219 | /**
220 | * Get controller scaffolder instance.
221 | *
222 | * @return string
223 | */
224 | public function getControllerScaffolder()
225 | {
226 | return new ControllerScaffolder($this->getEntity(), $this->getPrefix());
227 | }
228 |
229 | /**
230 | * Get form generator instance.
231 | *
232 | * @return string
233 | */
234 | public function getFormGenerator()
235 | {
236 | return new FormGenerator($this->getEntities(), $this->getFields());
237 | }
238 |
239 | /**
240 | * Get table dumper.
241 | *
242 | * @return mixed
243 | */
244 | public function getTableDumper()
245 | {
246 | if ($this->migrated) {
247 | return new TableDumper($this->getEntities());
248 | }
249 |
250 | if ($this->existing()) {
251 | return TableDumper::make($this->getEntities())
252 | ->except(['id', 'created_at', 'updated_at', 'deleted_at']);
253 | }
254 |
255 | return new FieldsDumper($fields);
256 | }
257 |
258 | /**
259 | * Generate views.
260 | */
261 | public function generateViews()
262 | {
263 | $this->generateViewLayout();
264 |
265 | if (!$this->confirm('Do you want to create view resources?')) {
266 | return;
267 | }
268 |
269 | foreach ($this->views as $view) {
270 | $this->generateView($view);
271 | }
272 | }
273 |
274 | /**
275 | * Generate a scaffold view.
276 | *
277 | * @param string $view
278 | */
279 | public function generateView($view)
280 | {
281 | $generator = new ViewGenerator([
282 | 'name' => $this->getPrefix('/').$this->getEntities().'/'.$view,
283 | 'extends' => str_replace('/', '.', $this->getViewLayout()),
284 | 'template' => '/scaffold/views/'.$view.'.stub',
285 | 'force' => $this->console->option('force'),
286 | ]);
287 |
288 | $generator->appendReplacement(array_merge($this->getControllerScaffolder()->toArray(), [
289 | 'lower_plural_entity' => strtolower($this->getEntities()),
290 | 'studly_singular_entity' => Str::studly($this->getEntity()),
291 | 'form' => $this->getFormGenerator()->render(),
292 | 'table_heading' => $this->getTableDumper()->toHeading(),
293 | 'table_body' => $this->getTableDumper()->toBody($this->getEntity()),
294 | 'show_body' => $this->getTableDumper()->toRows($this->getEntity()),
295 | ]));
296 |
297 | $generator->run();
298 |
299 | $this->console->info('View created successfully.');
300 | }
301 |
302 | /**
303 | * Append new route.
304 | */
305 | public function appendRoute()
306 | {
307 | if (!$this->confirm('Do you want to append new route?')) {
308 | return;
309 | }
310 |
311 | $contents = $this->laravel['files']->get($path = app_path('Http/routes.php'));
312 | $contents .= PHP_EOL."Route::group(['middleware' => ['web']], function () {";
313 | $contents .= PHP_EOL."\tRoute::resource('{$this->getRouteName()}', '{$this->getControllerName()}');";
314 | $contents .= PHP_EOL."});";
315 |
316 | $this->laravel['files']->put($path, $contents);
317 |
318 | $this->console->info('Route appended successfully.');
319 | }
320 |
321 | /**
322 | * Get route name.
323 | *
324 | * @return string
325 | */
326 | public function getRouteName()
327 | {
328 | $route = $this->getEntities();
329 |
330 | if ($this->console->option('prefix')) {
331 | $route = strtolower($this->getPrefix('/')).$route;
332 | }
333 |
334 | return $route;
335 | }
336 |
337 | /**
338 | * Get prefix name.
339 | *
340 | * @param string|null $suffix
341 | *
342 | * @return string|null
343 | */
344 | public function getPrefix($suffix = null)
345 | {
346 | $prefix = $this->console->option('prefix');
347 |
348 | return $prefix ? $prefix.$suffix : null;
349 | }
350 |
351 | /**
352 | * Run the migrations.
353 | */
354 | public function runMigration()
355 | {
356 | if ($this->confirm('Do you want to run all migration now?')) {
357 | $this->migrated = true;
358 |
359 | $this->console->call('migrate', [
360 | '--force' => $this->console->option('force'),
361 | ]);
362 | }
363 | }
364 |
365 | /**
366 | * Generate request classes.
367 | */
368 | public function generateRequest()
369 | {
370 | if (!$this->confirm('Do you want to create form request classes?')) {
371 | return;
372 | }
373 |
374 | foreach (['Create', 'Update'] as $request) {
375 | $name = $this->getPrefix('/').$this->getEntities().'/'.$request.Str::studly($this->getEntity()).'Request';
376 |
377 | $this->console->call('generate:request', [
378 | 'name' => $name,
379 | '--scaffold' => true,
380 | '--auth' => true,
381 | '--rules' => $this->existing() ? $this->getTableDumper()->toSchema() : $this->getFields(),
382 | '--force' => $this->console->option('force'),
383 | ]);
384 | }
385 | }
386 |
387 | /**
388 | * Run the generator.
389 | */
390 | public function run()
391 | {
392 | $this->generateModel();
393 | $this->generateMigration();
394 | $this->generateSeed();
395 | $this->generateRequest();
396 | $this->generateController();
397 | if (!$this->existing()) {
398 | $this->runMigration();
399 | }
400 | $this->generateViews();
401 | $this->appendRoute();
402 | }
403 | }
404 |
--------------------------------------------------------------------------------
/Scaffolders/ControllerScaffolder.php:
--------------------------------------------------------------------------------
1 | name = $name;
40 | $this->prefix = $prefix;
41 | $this->entity = $this->getEntity();
42 | }
43 |
44 | /**
45 | * Get entity name.
46 | *
47 | * @return string
48 | */
49 | public function getEntity()
50 | {
51 | return Str::singular(str_replace('controller', '', strtolower($this->name)));
52 | }
53 |
54 | /**
55 | * Get prefix as StudlyCase.
56 | *
57 | * @return string
58 | */
59 | public function getStudlyPrefix()
60 | {
61 | return Str::studly($this->prefix ?: '');
62 | }
63 |
64 | /**
65 | * Get entities name as lowercase.
66 | *
67 | * @return string
68 | */
69 | public function getLowerEntities()
70 | {
71 | return strtolower(Str::plural($this->entity));
72 | }
73 |
74 | /**
75 | * Get singular name of entity in lowercase.
76 | *
77 | * @return string
78 | */
79 | public function getLowerSingularEntity()
80 | {
81 | return strtolower(Str::singular($this->entity));
82 | }
83 |
84 | /**
85 | * Get entity name in StudlyCase.
86 | *
87 | * @return string
88 | */
89 | public function getStudlyEntity()
90 | {
91 | return Str::studly($this->entity);
92 | }
93 |
94 | /**
95 | * Get plural entity name in StudlyCase.
96 | *
97 | * @return string
98 | */
99 | public function getStudlyPluralEntity()
100 | {
101 | return Str::plural($this->getStudlyEntity());
102 | }
103 |
104 | /**
105 | * Get prefix with dot suffix.
106 | *
107 | * @return string
108 | */
109 | public function getPrefixDot()
110 | {
111 | return $this->prefix ? $this->prefix.'.' : '';
112 | }
113 |
114 | /**
115 | * Get prefix with slash suffix.
116 | *
117 | * @return string
118 | */
119 | public function getPrefixSlash()
120 | {
121 | return $this->prefix ? Str::studly($this->prefix.'\\') : '';
122 | }
123 |
124 | /**
125 | * Array of replacements.
126 | *
127 | * @return string
128 | */
129 | public function toArray()
130 | {
131 | return [
132 | 'prefix' => $this->prefix,
133 | 'entity' => $this->entity,
134 | 'lower_entities' => $this->getLowerEntities(),
135 | 'lower_singular_entity' => $this->getLowerSingularEntity(),
136 | 'studly_entity' => $this->getStudlyEntity(),
137 | 'studly_plural_entity' => $this->getStudlyPluralEntity(),
138 | 'prefix_dot' => $this->getPrefixDot(),
139 | 'prefix_slash' => $this->getPrefixSlash(),
140 | ];
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/SeedGenerator.php:
--------------------------------------------------------------------------------
1 | getBasePath().$this->getName().'.php';
32 | }
33 |
34 | /**
35 | * Get name of class.
36 | *
37 | * @return string
38 | */
39 | public function getName()
40 | {
41 | $name = parent::getName();
42 |
43 | $suffix = $this->master ? 'DatabaseSeeder' : 'TableSeeder';
44 |
45 | return $name.$suffix;
46 | }
47 |
48 | /**
49 | * Get root namespace.
50 | *
51 | * @return string
52 | */
53 | public function getRootNamespace()
54 | {
55 | return false;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Stub.php:
--------------------------------------------------------------------------------
1 | firstItem();
29 |
30 | return view('$PREFIX_DOT$$LOWER_ENTITIES$.index', compact('$LOWER_ENTITIES$', 'index'));
31 | }
32 |
33 | /**
34 | * Show the form for creating a new resource.
35 | *
36 | * @return Response
37 | */
38 | public function create()
39 | {
40 | return view('$PREFIX_DOT$$LOWER_ENTITIES$.create');
41 | }
42 |
43 | /**
44 | * Store a newly created resource in storage.
45 | *
46 | * @return Response
47 | */
48 | public function store(Create$STUDLY_ENTITY$Request $request)
49 | {
50 | $$LOWER_SINGULAR_ENTITY$ = $STUDLY_ENTITY$::create($request->all());
51 |
52 | return redirect()->route('$PREFIX_DOT$$LOWER_ENTITIES$.index');
53 | }
54 |
55 | /**
56 | * Display the specified resource.
57 | *
58 | * @param int $id
59 | * @return Response
60 | */
61 | public function show($id)
62 | {
63 | $$LOWER_SINGULAR_ENTITY$ = $STUDLY_ENTITY$::findOrFail($id);
64 |
65 | return view('$PREFIX_DOT$$LOWER_ENTITIES$.show', compact('$LOWER_SINGULAR_ENTITY$'));
66 | }
67 |
68 | /**
69 | * Show the form for editing the specified resource.
70 | *
71 | * @param int $id
72 | * @return Response
73 | */
74 | public function edit($id)
75 | {
76 | $$LOWER_SINGULAR_ENTITY$ = $STUDLY_ENTITY$::findOrFail($id);
77 |
78 | return view('$PREFIX_DOT$$LOWER_ENTITIES$.edit', compact('$LOWER_SINGULAR_ENTITY$'));
79 | }
80 |
81 | /**
82 | * Update the specified resource in storage.
83 | *
84 | * @param int $id
85 | * @return Response
86 | */
87 | public function update(Update$STUDLY_ENTITY$Request $request, $id)
88 | {
89 | $$LOWER_SINGULAR_ENTITY$ = $STUDLY_ENTITY$::findOrFail($id);
90 |
91 | $$LOWER_SINGULAR_ENTITY$->update($request->all());
92 |
93 | return redirect()->route('$PREFIX_DOT$$LOWER_ENTITIES$.index');
94 | }
95 |
96 | /**
97 | * Remove the specified resource from storage.
98 | *
99 | * @param int $id
100 | * @return Response
101 | */
102 | public function destroy($id)
103 | {
104 | $$LOWER_SINGULAR_ENTITY$ = $STUDLY_ENTITY$::findOrFail($id);
105 |
106 | $$LOWER_SINGULAR_ENTITY$->delete();
107 |
108 | return redirect()->route('$PREFIX_DOT$$LOWER_ENTITIES$.index');
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/Stubs/filter.stub:
--------------------------------------------------------------------------------
1 |
3 | {!! Form::label('$NAME$', '', ['class' => 'col-md-2 control-label']) !!}
4 |
5 | {!! Form::checkbox('$NAME$') !!}
6 | $LABEL$
7 |
8 |
--------------------------------------------------------------------------------
/Stubs/form/email.stub:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Stubs/form/input.stub:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Stubs/form/password.stub:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Stubs/form/radio.stub:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Stubs/form/select.stub:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Stubs/form/text.stub:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Stubs/form/textarea.stub:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Stubs/migration/add.stub:
--------------------------------------------------------------------------------
1 | increments('id');
18 | $FIELDS$
19 | $table->timestamps();
20 | });
21 | }
22 |
23 | /**
24 | * Reverse the migrations.
25 | *
26 | * @return void
27 | */
28 | public function down()
29 | {
30 | Schema::drop('$TABLE$');
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/Stubs/migration/delete.stub:
--------------------------------------------------------------------------------
1 | increments('id');
28 | $FIELDS$
29 | $table->timestamps();
30 | });
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/Stubs/migration/pivot.stub:
--------------------------------------------------------------------------------
1 | integer('$COLUMN_ONE$_id')->unsigned()->index();
18 | $table->foreign('$COLUMN_ONE$_id')->references('id')->on('$TABLE_ONE$')->onDelete('cascade');
19 | $table->integer('$COLUMN_TWO$_id')->unsigned()->index();
20 | $table->foreign('$COLUMN_TWO$_id')->references('id')->on('$TABLE_TWO$')->onDelete('cascade');
21 | $TIMESTAMP$
22 | });
23 | }
24 |
25 | /**
26 | * Reverse the migrations.
27 | *
28 | * @return void
29 | */
30 | public function down()
31 | {
32 | Schema::drop('$TABLE_PIVOT$');
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/Stubs/migration/plain.stub:
--------------------------------------------------------------------------------
1 |
3 | $LABEL$ |
4 | {!! $$VAR$->$COLUMN$ !!} |
5 |
--------------------------------------------------------------------------------
/Stubs/scaffold/views/create.stub:
--------------------------------------------------------------------------------
1 | @extends('$EXTENDS$')
2 |
3 | @section('content')
4 |
5 |
6 |
7 | Add New $STUDLY_SINGULAR_ENTITY$
8 |
11 |
12 |
13 | @include('$PREFIX_DOT$$LOWER_PLURAL_ENTITY$.form')
14 |
15 |
16 |
17 | @stop
--------------------------------------------------------------------------------
/Stubs/scaffold/views/edit.stub:
--------------------------------------------------------------------------------
1 | @extends('$EXTENDS$')
2 |
3 | @section('content')
4 |
5 |
6 |
7 | Edit $STUDLY_SINGULAR_ENTITY$
8 |
11 |
12 |
13 | @include('$PREFIX_DOT$$LOWER_PLURAL_ENTITY$.form', ['model' => $$LOWER_SINGULAR_ENTITY$])
14 |
15 |
16 |
17 | @stop
--------------------------------------------------------------------------------
/Stubs/scaffold/views/form.stub:
--------------------------------------------------------------------------------
1 | @if (count($errors) > 0)
2 |
3 |
Whoops! There were some problems with your input.
4 |
5 | @foreach ($errors->all() as $error)
6 | - {{ $error }}
7 | @endforeach
8 |
9 |
10 | @endif
11 |
12 |
--------------------------------------------------------------------------------
/Stubs/scaffold/views/index.stub:
--------------------------------------------------------------------------------
1 | @extends('$EXTENDS$')
2 |
3 | @section('content')
4 |
5 |
6 | All $STUDLY_PLURAL_ENTITY$
7 |
10 |
11 |
12 |
13 | # |
14 | $TABLE_HEADING$
15 | Created At |
16 | Action |
17 |
18 |
19 | @foreach ($$LOWER_PLURAL_ENTITY$ as $$LOWER_SINGULAR_ENTITY$)
20 |
21 | {!! $index !!} |
22 | $TABLE_BODY$
23 | {!! $$LOWER_SINGULAR_ENTITY$->created_at !!} |
24 |
25 |
26 | {!! Form::open(['method' => 'DELETE', 'route' => ['$PREFIX_DOT$$LOWER_PLURAL_ENTITY$.destroy', $$LOWER_SINGULAR_ENTITY$->id]]) !!}
27 |
28 |
29 |
30 | {!! Form::close() !!}
31 |
32 | |
33 |
34 |
35 | @endforeach
36 |
37 |
38 |
41 |
42 | @stop
--------------------------------------------------------------------------------
/Stubs/scaffold/views/show.stub:
--------------------------------------------------------------------------------
1 | @extends('$EXTENDS$')
2 |
3 | @section('content')
4 |
5 |
6 | Show $STUDLY_SINGULAR_ENTITY$
7 |
11 |
12 |
13 |
14 | ID |
15 | {!! $$LOWER_SINGULAR_ENTITY$->id !!} |
16 |
17 | $SHOW_BODY$
18 |
19 | Created At |
20 | {!! $$LOWER_SINGULAR_ENTITY$->created_at !!} |
21 |
22 |
23 |
24 | @stop
--------------------------------------------------------------------------------
/Stubs/seed.stub:
--------------------------------------------------------------------------------
1 | call("OthersTableSeeder");
18 | }
19 |
20 | }
--------------------------------------------------------------------------------
/Stubs/view.stub:
--------------------------------------------------------------------------------
1 | @extends('$EXTENDS$')
2 |
3 | @section('$SECTION$')
4 |
5 | $CONTENT$
6 |
7 | @endsection
--------------------------------------------------------------------------------
/Stubs/views/master.stub:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Laravel
8 |
9 |
10 |
11 |
12 |
13 |
14 |
18 |
19 |
22 |
23 |
24 |
25 | @yield('content')
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/ViewGenerator.php:
--------------------------------------------------------------------------------
1 | master) {
27 | $this->stub = 'views/master';
28 | }
29 | }
30 |
31 | /**
32 | * Get base path of destination file.
33 | *
34 | * @return string
35 | */
36 | public function getBasePath()
37 | {
38 | return base_path().'/resources/views/';
39 | }
40 |
41 | /**
42 | * Get destination path for generated file.
43 | *
44 | * @return string
45 | */
46 | public function getPath()
47 | {
48 | return $this->getBasePath().strtolower($this->getName()).'.blade.php';
49 | }
50 |
51 | /**
52 | * Get stub template for generated file.
53 | *
54 | * @return string
55 | */
56 | public function getStub()
57 | {
58 | if ($this->plain) {
59 | return $this->getPath();
60 | }
61 |
62 | if ($template = $this->template) {
63 | return Stub::create($template, $this->getReplacements())->render();
64 | }
65 |
66 | return parent::getStub();
67 | }
68 |
69 | /**
70 | * Get root namespace.
71 | *
72 | * @return string
73 | */
74 | public function getRootNamespace()
75 | {
76 | return '';
77 | }
78 |
79 | /**
80 | * Get template replacements.
81 | *
82 | * @return array
83 | */
84 | public function getReplacements()
85 | {
86 | $replaces = [
87 | 'extends' => $this->extends,
88 | 'section' => $this->section,
89 | 'content' => $this->content,
90 | ];
91 |
92 | return $this->customReplacements + $replaces;
93 | }
94 |
95 | /**
96 | * Append a custom replacements to this instance.
97 | *
98 | * @param array $replacements
99 | *
100 | * @return self
101 | */
102 | public function appendReplacement(array $replacements)
103 | {
104 | $this->customReplacements = $replacements;
105 |
106 | return $this;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "pingpong/generators",
3 | "description": "Laravel Generators",
4 | "license": "BSD-3-Clause",
5 | "keywords": [
6 | "laravel",
7 | "generators",
8 | "pingpong"
9 | ],
10 | "authors": [
11 | {
12 | "name": "Pingpong Labs",
13 | "email": "pingpong.labs@gmail.com"
14 | }
15 | ],
16 | "require": {
17 | "php": ">=5.4.0",
18 | "illuminate/filesystem": "5.2.*",
19 | "illuminate/support": "5.2.*",
20 | "pingpong/support": "2.2.*@dev",
21 | "doctrine/dbal": "~2.5"
22 | },
23 | "require-dev": {
24 | "mockery/mockery": "~0.9",
25 | "phpunit/phpunit": "~4"
26 | },
27 | "autoload": {
28 | "psr-4": {
29 | "Pingpong\\Generators\\": ""
30 | }
31 | },
32 | "minimum-stability": "stable"
33 | }
34 |
--------------------------------------------------------------------------------
/config.php:
--------------------------------------------------------------------------------
1 | base_path('resources/pingpong/generators/stubs')
5 | ];
--------------------------------------------------------------------------------