Skip to content

Commit 9d31ab3

Browse files
feature/artisan-command (#15)
* Creating command uuid:make:model Signed-off-by: Nathanael Yusuf Tjahjanadi <[email protected]> * Creating package autodiscovery Signed-off-by: Nathanael Yusuf Tjahjanadi <[email protected]> * Style cleanup to pass travis-ci test. Signed-off-by: Nathanael Yusuf Tjahjanadi <[email protected]> * Updated README for additional install instruction Signed-off-by: Nathanael Yusuf Tjahjanadi <[email protected]> * Extended base laravel model class * Adding @nathanaelytj as author Co-authored-by: Nathanael Yusuf Tjahjanadi <[email protected]> * Added return type and docblock * Updated README.md documentation * Closes #2
1 parent 3406ad2 commit 9d31ab3

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ class BlogPost extends Model
167167
}
168168
```
169169

170+
### Creating models
171+
172+
In addition of the `make:model` artisan command, you will now have access to
173+
`uuid:make:model` which has all the functionality of the standard `make:model`
174+
command (with exception of not being able to create a pivot model):
175+
176+
```bash
177+
php artisan uuid:make:model Models/Post --all
178+
```
179+
170180
## Running the tests
171181

172182
To run the test suite you can use the following commands:

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,12 @@
4747
"test:style": "php-cs-fixer fix --config=.php_cs --allow-risky=yes --dry-run --diff --verbose",
4848
"test:unit": "phpunit",
4949
"fix:style": "php-cs-fixer fix --config=.php_cs --allow-risky=yes --diff --verbose"
50+
},
51+
"extra": {
52+
"laravel": {
53+
"providers": [
54+
"GoldSpecDigital\\LaravelEloquentUUID\\UuidServiceProvider"
55+
]
56+
}
5057
}
5158
}

src/Console/Stubs/model.stub

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use GoldSpecDigital\LaravelEloquentUUID\Database\Eloquent\Model;
6+
7+
class DummyClass extends Model
8+
{
9+
//
10+
}

src/Console/UuidModelCommand.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace GoldSpecDigital\LaravelEloquentUUID\Console;
6+
7+
use Illuminate\Foundation\Console\ModelMakeCommand;
8+
9+
class UuidModelCommand extends ModelMakeCommand
10+
{
11+
/**
12+
* The console command name.
13+
*
14+
* @var string
15+
*/
16+
protected $name = 'uuid:make:model';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Create a new Eloquent UUID model class';
24+
25+
/**
26+
* The type of class being generated.
27+
*
28+
* @var string
29+
*/
30+
protected $type = 'UUID Model';
31+
32+
/**
33+
* Get the stub file for the generator.
34+
*
35+
* @return string
36+
*/
37+
protected function getStub(): string
38+
{
39+
return __DIR__ . '/stubs/model.stub';
40+
}
41+
42+
/**
43+
* Get the console command options.
44+
*
45+
* @return array
46+
*/
47+
protected function getOptions(): array
48+
{
49+
// Remove the pivot option from the parent class.
50+
return array_filter(
51+
parent::getOptions(),
52+
function (array $option): bool {
53+
return $option[0] !== 'pivot';
54+
}
55+
);
56+
}
57+
58+
/**
59+
* Get the value of a command option.
60+
*
61+
* @param string|null $key
62+
* @return string|array|bool|null
63+
*/
64+
public function option($key = null)
65+
{
66+
if ($key === 'pivot') {
67+
return false;
68+
}
69+
70+
return parent::option($key);
71+
}
72+
}

src/UuidServiceProvider.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace GoldSpecDigital\LaravelEloquentUUID;
6+
7+
use GoldSpecDigital\LaravelEloquentUUID\Console\UuidModelCommand;
8+
use Illuminate\Support\ServiceProvider;
9+
10+
class UuidServiceProvider extends ServiceProvider
11+
{
12+
/**
13+
* Bootstrap any application services.
14+
*/
15+
public function boot(): void
16+
{
17+
if ($this->app->runningInConsole()) {
18+
$this->commands([
19+
UuidModelCommand::class,
20+
]);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)