Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add inbound option to CastMakeCommand #41838

Merged
merged 2 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Illuminate/Foundation/Console/CastMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Foundation\Console;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class CastMakeCommand extends GeneratorCommand
{
Expand Down Expand Up @@ -45,7 +46,9 @@ class CastMakeCommand extends GeneratorCommand
*/
protected function getStub()
{
return $this->resolveStubPath('/stubs/cast.stub');
return $this->option('inbound')
? $this->resolveStubPath('/stubs/cast.inbound.stub')
: $this->resolveStubPath('/stubs/cast.stub');
}

/**
Expand All @@ -71,4 +74,16 @@ protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Casts';
}

/**
* Get the console command arguments.
*
* @return array
*/
protected function getOptions()
{
return [
['inbound', null, InputOption::VALUE_OPTIONAL, 'Generate an inbound cast class'],
];
}
}
22 changes: 22 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/cast.inbound.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace {{ namespace }};

use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes;

class {{ class }} implements CastsInboundAttributes
{
/**
* Prepare the given value for storage.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function set($model, string $key, $value, array $attributes)
{
return $value;
}
}