I try to render a @foreach loop in a markdown template. But I don't get it to work. I found this Laravel- use @foreach in markdown mail, but it didn't take me further.
I studied the Laravel docs, but it seems that I'm unable to find my issue.
I try to generate a mail with all the information from the supplier-table. Therefore I use the Supplier Class.
Maybe someone could open my eyes or could give me a hint in the right direction.
Route:
Route::get('/mail',function(){
$suppliers = App\ModelSupplier\Supplier::all();
return new App\Mail\Supplier\Certificates($suppliers);
});
Mail-Class:
namespace App\Mail\Supplier;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\ModelSupplier\Supplier;
class Certificates extends Mailable
{
use Queueable, SerializesModels;
public $supplier;
public function __construct(Supplier $supplier)
{
//
$this->supplier = $supplier;
}
public function build()
{
return $this->markdown('email.supplier.test');
}
}
Markdown-File:
# Certificate:
@component('mail::table')
|No. | Company | Address
|:--------|:--------|----------:
@foreach($supplier as $detail)
| {{$detail->no}} | {{$detail->company}} | {{$detail->address}}
@endforeach
@endcomponent
I'm receiving this error:
Argument 1 passed to App\Mail\Supplier\Certificates::__construct()
must be an instance of App\ModelSupplier\Supplier, instance of
Illuminate\Database\Eloquent\Collection given, called in C:\xampp\htdocs
\pps\routes\mail.php on line 7
Am I completely wrong?
Thank you in advance.