/** * Execute the console command. * * @return mixed */ public function handle() { $_key = $this->argument('key'); $_blueprint = $this->argument('blueprint'); $_file = $this->argument('file'); $_creator = $this->argument('creator'); $_header = escapeshellarg($this->argument('header')); $blueprint = Blueprint::find($_blueprint); if (!$blueprint) { Log::error("la encuesta con id: {$_blueprint} no se encontró"); return; } $blueprint->sending_emails = 1; $blueprint->update(); $counter = 0; Excel::load("storage/app/" . $_key . ".xlsx", function ($reader) use($blueprint, $counter, $_key, $_header) { $reader->each(function ($row) use($blueprint, $counter, $_key, $_header) { if (trim($row->correo) != "" && filter_var($row->correo, FILTER_VALIDATE_EMAIL)) { $form_key = str_replace("/", "", Hash::make('blueprint' . $blueprint->id . $row->correo)); $applicant = Applicant::firstOrCreate(["blueprint_id" => $blueprint->id, "form_key" => $form_key, "user_email" => $row->correo, "temporal_key" => $_key]); $path = base_path(); exec("php {$path}/artisan email:send {$applicant->id} {$_header} > /dev/null &"); $update = $blueprint->emails + 1; $blueprint->emails = $update; $blueprint->update(); } }); })->first(); $total = Applicant::where("temporal_key", $_key)->count(); $mailgun = new MailgunEmail(["blueprint" => $blueprint->id, "emails" => $total]); $mailgun->save(); $blueprint->sending_emails = 0; $blueprint->update(); }
public function resetSurvey(Request $request) { $applicant = Applicant::where('form_key', $request->input('form_key'))->first(); if ($applicant) { return response()->json($applicant->answers()->delete()); } else { return response()->json(false); } }