public function renderEmail($title_slug, Request $request) { $touch = Touch::where('title_slug', '=', $title_slug)->first(); if (!$touch) { abort(404); } if ($request->input('email')) { $salted_id = $request->input('email'); } else { $salted_id = null; } if ($salted_id) { $email = Email::where('salted_id', $salted_id)->first(); $html = preg_replace_callback('/{{[^}]*}}/', function ($matches) use($email) { return collect($matches)->map(function ($match) use($email) { $match = str_replace('{{', '', $match); $match = str_replace('}}', '', $match); $match = trim($match); if ($match === 'tracking') { return $email->salted_id; } return $email->contact->{$match}; })->first(); }, $email->touch->template_html); } else { $html = $touch->template_html; } return view('emails.template')->with(['template_html' => $html, 'salted_id' => $salted_id, 'campaign' => $touch->campaign, 'email' => false, 'preview_text' => $touch->preview_text]); }
public function engage($name, Request $request) { $email = $request->input('email') ? Email::where('salted_id', '=', $request->input('email'))->first() : null; $touch = $email ? $email->touch : Touch::where('title_slug', '=', $name)->first(); $campaign = $touch->campaign; if ($email && $email->trackable) { Action::firstOrCreate(['action' => 'clicked register', 'contact_id' => $email->contact->id, 'campaign_id' => $email->campaign->id, 'touch_id' => $email->touch_id]); } return view()->make('signups.engage')->with(['campaign' => $campaign, 'email' => $email]); }