Skip to content

Commit 8d38396

Browse files
[9.x] Add inbound option to CastMakeCommand (#41838)
* feat: add inbound option to CastMakeCommand * Update CastMakeCommand.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 9d3f03b commit 8d38396

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/Illuminate/Foundation/Console/CastMakeCommand.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Foundation\Console;
44

55
use Illuminate\Console\GeneratorCommand;
6+
use Symfony\Component\Console\Input\InputOption;
67

78
class CastMakeCommand extends GeneratorCommand
89
{
@@ -45,7 +46,9 @@ class CastMakeCommand extends GeneratorCommand
4546
*/
4647
protected function getStub()
4748
{
48-
return $this->resolveStubPath('/stubs/cast.stub');
49+
return $this->option('inbound')
50+
? $this->resolveStubPath('/stubs/cast.inbound.stub')
51+
: $this->resolveStubPath('/stubs/cast.stub');
4952
}
5053

5154
/**
@@ -71,4 +74,16 @@ protected function getDefaultNamespace($rootNamespace)
7174
{
7275
return $rootNamespace.'\Casts';
7376
}
77+
78+
/**
79+
* Get the console command arguments.
80+
*
81+
* @return array
82+
*/
83+
protected function getOptions()
84+
{
85+
return [
86+
['inbound', null, InputOption::VALUE_OPTIONAL, 'Generate an inbound cast class'],
87+
];
88+
}
7489
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes;
6+
7+
class {{ class }} implements CastsInboundAttributes
8+
{
9+
/**
10+
* Prepare the given value for storage.
11+
*
12+
* @param \Illuminate\Database\Eloquent\Model $model
13+
* @param string $key
14+
* @param mixed $value
15+
* @param array $attributes
16+
* @return mixed
17+
*/
18+
public function set($model, string $key, $value, array $attributes)
19+
{
20+
return $value;
21+
}
22+
}

0 commit comments

Comments
 (0)