public function store() { $user_id = \Auth::user()->id; $slug = str_slug(Input::get('title')); $poll = new PollsDemand(); $poll->title = Input::get('title'); $poll->default_image_url = Input::get('default_image_url'); $poll->community_id = Input::get('community_id'); $poll->owner_user_id = $user_id; $poll->slug = $slug; $poll->type = Input::get('poll_type'); $poll->is_activated = true; $poll->save(); $pollOptions = []; foreach (Input::get('pollOptions') as $pollOption) { if (isset($pollOption['title'])) { $pollOptions[] = array('polls_demand_id' => $poll->id, 'user_id' => $user_id, 'title' => $pollOption['title'], 'image_url' => $pollOption['image_url'], 'product_url' => $pollOption['product_url'], 'description' => $pollOption['description']); } } $poll->details()->insert($pollOptions); return response()->json(['success' => true, 'redirect' => \URL::to('/') . '/vote/' . $slug . '/' . $poll->id]); }