Esempio n. 1
0
 public function save()
 {
     if (!$this->isValid()) {
         return false;
     }
     return DB::transaction(function () {
         $this->topic->update(['poll_title' => $this->params['title'], 'poll_start' => Carbon::now(), 'poll_length' => ($this->params['length_days'] ?? 0) * 3600, 'poll_max_options' => $this->params['max_options'], 'poll_vote_change' => $this->params['vote_change'] ?? false]);
         $this->topic->pollVotes()->delete();
         $this->topic->pollOptions()->delete();
         for ($i = 0; $i < count($this->params['options']); $i++) {
             PollOption::create(['topic_id' => $this->topic->topic_id, 'poll_option_id' => $i, 'poll_option_text' => $this->params['options'][$i]]);
         }
         return true;
     });
 }