Skip to content

Instantly share code, notes, and snippets.

@Damian89
Last active January 29, 2021 18:23
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 Damian89/115d27a1aa5f9d91c8aa5cd139795155 to your computer and use it in GitHub Desktop.
Save Damian89/115d27a1aa5f9d91c8aa5cd139795155 to your computer and use it in GitHub Desktop.
Wrong...
<?php
namespace App\Console\Commands\Misc;
use App\Models\Target;
use Illuminate\Console\Command;
class DoSomething extends Command
{
protected $signature = 'do:something {--target= : Target ID}';
protected $description = 'Does something';
protected Target $target;
protected array $data = [];
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->target = Target::findOrFail(
$this->option('target')
);
$this->doSomethingElse();
$this->nowUseData();
return 0;
}
protected function doSomethingElse(): void {
// some work, and we set data
$this->data[] = ["target" => $this->target->id, "something" => "something valuable for target ".$this->target->id];
$this->data[] = ["target" => $this->target->id, "something" => "something else also valuable".$this->target->id];
}
protected function nowUseData(): void {
// data is set, now do something with it, e.g. notification
Notification::route('mail', 'taylor@example.com')->notify(new NewDataNotification($this->target, $this->data));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment