I have this question of how to send several data in a array
and that when invoking this data in the template that was sent can declare them in different sections, this is what I have
This is my Mailable
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class EncuestaSolvex extends Mailable
{
use Queueable, SerializesModels;
public $data;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->from('[email protected]')
->subject('Resultados de Encuesta')
->markdown('emails.encuesta')
->with(['data', $this->data]);
}
}
This is the driver part
public function email(Request $request)
{
$email=DB::table('usuario')
->where('id_usu', '=', $request->get('id'))
->get();
$nombre=DB::table('usuario')
->where('id_usu', '=', $request->get('id'))
->get();
$usuario = Usuario::findOrFail($email[0]->id_usu);
$data = array('email' => $usuario->email,'nombre' => $usuario->nombre);
Mail::to($usuario->email)->send(new EncuestaSolvex($data));
return "success";
}
and this is the template that is sent by email
@component('mail::message')
# Introduction
The body of your message.
@foreach ($data as $data)
<ul>
Nombre: {{ $data }}
</ul>
@endforeach
{{-- Nomre: {{ $data }}
--}}
@component('mail::button', ['url' => ''])
Button Text
@endcomponent
Thanks,<br>
{{ config('app.name') }}
@endcomponent
When I want to take just one data, say name or email, it does not leave me, or rather I do not know how to do it, I can not put $data-nombre
because it marks me that I try to invoke a non-object, so in what way could it?