public function doCampaignAddContent(Request $request) { $campaign = Campaign::findOrFail($request->input('campaign_id')); $campaign_text_sections = substr_count($campaign->template->content, '<!! Section_'); $campaign_image_sections = substr_count($campaign->template->content, '<!! Image_'); for ($i = 0; $i < $campaign_text_sections; $i++) { $section_number = $i + 1; $campaign->updateSection($section_number, 'text', $request->input('section_' . $section_number)); } for ($i = 0; $i < $campaign_image_sections; $i++) { $section_number = $i + 1; if ($request->hasFile('image_' . $section_number)) { $filename = CampaignTemplateSection::storeImage($request->file('image_' . $section_number)); $campaign->updateSection($section_number, 'image', $filename); } } return redirect()->to('marketing/campaign/' . $campaign->id . '/preview'); }
public function updateSection($section_number, $type, $content) { if ($this->template_sections()->where('section_id', $section_number)->where('type', $type)->count() > 0) { $section = $this->template_sections()->where('section_id', $section_number)->where('type', $type)->first(); $section->content = $content; $section->save(); } else { $section = new CampaignTemplateSection(); $section->section_id = $section_number; $section->type = $type; $section->content = $content; $section->campaign_id = $this->id; $section->save(); } }