I've made a mail function with an try/catch situation. It checks if the mail template exists, if not it needs to return redirect / back to the page with a message(return redirect('dashboard')->with('status', "Mail doesn't exists");
)
Is it possible to redirect with a variable using a twig page? Or is there just something that I am doing wrong?
This is my mail function(DashboardController.php)
public function MailContact($date_id, $contact_id)
{
try
{
$contact = Contact::find($contact_id);
$date = Date::find($date_id);
$mail = Mails::where('datetype_id', $date->datetype_id)->first();
$html = $mail->html;
Mail::to($contact->email)->send(new Anniversary($html));
return redirect('dashboard');
}
catch(\Exception $ex )
{
return redirect('dashboard')->with("Mail doesn't exists");
}
}
This is the twig page('dashboard.twig')
<div class="box-body no-padding" style="width: 100%; padding-top:20px;">
<ul class="telephoneKingList" style=" display: inline-block;
width: 100%;">
{% for dates in datestodayUser %}
{% if dates is not empty %}
<li data-id="{{ dates.id }}">
{{ dates.contact.fullname }}, {{ dates.contact.relation.company }} <br>
{{ dates.description }}<br>
{# Place where Error needs to be #}
<a role="button" id="edit-button" href="/dashboard/mail/{{ dates.id }}/{{ dates.contact.id }}" class="btn btn-primary btn-sm"><i class="fa fa-envelope"></i></a>
</li>
<hr>
{% endif %}
{% else %}
<li>
Geen data beschikbaar.
</li>
{% endfor %}
</ul>