with('entries', $entries)
->with('parser', $parser);
}
/**
* Creates a new guestbook entry
*
* @param Request $request
* @return RedirectResponse
* @throws ValidationException
*/
public function addEntry(Request $request): RedirectResponse {
$newEntry = GuestbookEntry::create($request);
$email = (new MailtrapEmail())
->from(new Address("wah@wah.moe", "wah dot moe"))
->to(new Address("roscoe@wah.moe", "Roscoe D. Wah"))
->subject("New Guestbook Entry!")
->category("Guestbook entry")
->html('
| Name: | '.htmlentities($newEntry->name).' |
| IP: | '.$newEntry->ip.' |
| Agent: | '.htmlentities($newEntry->agent).' |
| Message: | '.htmlentities($newEntry->message).' |
')
->text('Name: '.htmlentities($newEntry->name).
'IP: '.$newEntry->ip.
'Agent: '.htmlentities($newEntry->agent).
'Message: '.htmlentities($newEntry->message)
);
MailtrapClient::initSendingEmails(
apiKey: config('services.mailtrap-sdk.apiKey')
)->send($email);
return back()->with('success', 'Entry submitted successfully!');
}
public function destroy($id): RedirectResponse {
$entry = GuestbookEntry::findOrFail($id);
$entry->delete();
return redirect()->route('guestbook');
}
public function flag($id): RedirectResponse {
$entry = GuestbookEntry::where("id", $id)->get()->first;
$entry->update([
"flagged" => !$entry->flagged,
]);
return redirect()->route('guestbook');
}
}