Skip to content

Conversation

@shaedrich
Copy link
Contributor

like, for example, with \Illuminate\Support\Facades\Config (#50140) and \Illuminate\Support\Arr (#55567)

Enhancements

  • return value is typed
  • when value has unexpected type, an exception is thrown

Example

<?php

namespace App\Console\Commands;

use App\Models\User;
use App\Support\DripEmailer;
use Illuminate\Console\Command;
 
class SendEmails extends Command
{
    protected $signature = 'mail:send {user} {--flag} {--subject=} {--cc=*}';
    protected $description = 'Send a marketing email to a user';
 
    /**
     * Execute the console command.
     * 
     * @param int[] $cc
     */
    public function handle(
        #[Argument('user')] int $userId,
        #[Option('flag') bool $flag,
        #[Option('cc') array $cc,
        #[Option('subject') string $subject = 'Default subject',
        DripEmailer $drip,
    ): void {
        $user = User::find($userId);
        $cc = User::whereIn('id', $cc)->get();

        if ($flag) {
            // do something
        }

        $drip->send($user, $cc, $subject);
    }
}

@taylorotwell
Copy link
Member

Maybe I'm crazy but can you not just type options and arguments like this:

$foo = (string) $this->option('bar');

@shaedrich
Copy link
Contributor Author

Same goes with many other contextual other attributes in controllers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants