Abdan Syakuro
Abdan Syakuro

Reputation: 1054

Undefined variable on view mailing in Laravel 5.4

Hi guys i'm trying to mail on my system and there's problem on view which is undifined variable of data. i'm trying to parsing data to view, but it seems to be problem. here is my code of mailing

Mail::to($data['email'])->send(new TagihanMail(),['data' => $data]);

and here's my view

@component('mail::message')
# TAGIHAN PEMBAYARAN

Berikut tagihan anda untuk pembayaran


@component('mail::button', ['url' => ''])
{{ $data['nomor_tagihan'] }}
@endcomponent

@component('mail::table')
test
@endcomponent

Terimakasih,<br>
Panitia
@endcomponent

hope u guys can help me.

Upvotes: 1

Views: 1437

Answers (2)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

You can use:

Mail::to($data['email'])->send(new TagihanMail($data));

and in your TagihanMail you can use:

public function __construct($data)
{
   $this->data = $data;
}

public function build()
{
     return $this->view('your-view-here')->with(['data' => $this->data]);
}

Upvotes: 3

Niklesh Raut
Niklesh Raut

Reputation: 34914

Try to pass view name directly, like this.

Mail::to($data['email'])->send('emails.view_name',['data' => $data]);

Upate

You can pass data like this

$request = ['data' => $data];
Mail::to($data['email'])->send(new TagihanMail($request));

Upvotes: 0

Related Questions