/** * Execute the command. * * @param ProjectRepositoryInterface $repository * @param Dispatcher $event */ public function handle(ProjectRepositoryInterface $repository, Dispatcher $event) { /** * Check if Draft already have a project */ if ($project = $this->draft->project) { /** * Create Next Stage */ switch ($this->draft->type) { case 'synapse': $this->dispatch(new CreateSynapseCommand($project->id, $this->draft->toArray())); break; case 'script': $this->dispatch(new CreateScriptCommand($project->id, $this->draft->toArray())); break; } } else { /** * Create Project */ $command = new CreateProjectCommand($this->draft->user, $this->draft->toArray()); $this->dispatch($command); } /** * Delete Draft */ $command = new DeleteDraftCommand($this->draft); $this->dispatch($command); }
/** * Create a Draft * * @param int|null $project_id * @param int $user_id * @param int $type * @param array $fields * @return Draft */ public function create($project_id, $user_id, $type, array $fields) { $project = $this->model->setAttribute('project_id', $project_id)->setAttribute('user_id', $user_id)->setAttribute('type', $type)->fill($fields); $project->save(); return $project; }