Skip to content

Instantly share code, notes, and snippets.

@carestad
Created August 28, 2023 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carestad/0986c44ed52fd5a48795b6aeb72820fd to your computer and use it in GitHub Desktop.
Save carestad/0986c44ed52fd5a48795b6aeb72820fd to your computer and use it in GitHub Desktop.
Laravel trait to get only self-defined options for command
<?php
namespace App\Console\Commands\Traits;
use Illuminate\Support\Arr;
trait CommandTrait
{
/**
* Get the self-defined options for the command, e.g. exclude Laravel/Symfony's default options
*/
protected function definedOptions(): array
{
// Get application default options, so we can exclude them from results
$defaultOptions = $this->getApplication()->getDefinition()->getOptions();
return Arr::except($this->options(), array_keys($defaultOptions));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment