protected function save($command) { $message = new Message(); $message->message = $command->message; $ticket = new Ticket(); $ticket->subject = $command->subject; $ticket->name = $command->name; $ticket->email = $command->email; $ticket->setCategory(Category::find($command->category_id)); // Need repo $ticket->setStaffer(Staffer::find($command->staffer_id)); // Need repo $ticket->addMessage($message); $this->repository->save($ticket); $this->dispatcher->dispatch($ticket->flushEvents()); }
/** * Just a test method */ public function addstaff() { // Staffer ID 2 doesn't have category ID 2 $staffer = \Hex\Staff\Staffer::with('categories')->find(3); // Ticket ID 1 is assigned category ID 2 $ticket = \Hex\Tickets\Ticket::find(1); // This should fail, since staffer doesn't have // category 2 //$ticket->setStaffer( $staffer ); // We want this to reach the die() statement // Staffer 2 (assigned to ticket 1) doesn't have category 2 $category = \Hex\Tickets\Category::find(2); $ticket->setCategory($category); $ticket->setStaffer($staffer); /* try...catch */ $ticket->save(); /* around this */ }