Last active
January 29, 2021 18:23
-
-
Save Damian89/115d27a1aa5f9d91c8aa5cd139795155 to your computer and use it in GitHub Desktop.
Wrong...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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