After a day of working with Laravel I've created an application that let users create a request as a form that will be stored in my database. After creating a request (store) the input will also be send by mail.
What I would like is to send this data as a cvs (or MS Excel) file. I've found this tool http://www.maatwebsite.nl/laravel-excel/docs but I don't think I can use this to mail it. Because I am new to the laravel framework (and also OOP) I have no idea how I can manage this. The mail function is working, as I recieve a mail with my data.
Controller
\Mail::to('johndoe@info.com')->send(new Aanvraag($aanvraag));
Mail (Aanvraag.php)
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class Aanvraag extends Mailable
{
use Queueable, SerializesModels;
public $aanvraag;
public function __construct($aanvraag)
{
$this->aanvraag = $aanvraag;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mails.aanvraag');
}
}
The mail view
<!DOCTYPE html>
<html>
<head>
<title>Mail</title>
</head>
<body>
<h1>De volgende aanvraag is gedaan:</h1>
<table class="table table-responsive table-striped table-bordered">
<thead>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Begin datum</th>
<th>Eind datum</th>
<th>Account</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
via Gijsberts