Home > Net >  How Send parameter in controller to view in Laravel 8 Mail
How Send parameter in controller to view in Laravel 8 Mail

Time:10-27

i create system in Laravel 8 .in Case it have option admin user register inside system. I need send email to create user with email and passcode.i case i create php mail class as below

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class RegisterMail extends Mailable
{
    use Queueable, SerializesModels;


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

    public function build()
    {
        return $this->markdown('emails.register')
               ->subject('Register SLeAgro Agricultural Product Distribution System');
    }
}

so in user creation controller i access mail class as below

     $data1 = [
               'email' => $request->email,
               'password' => $code
            ];
    
            $mail = new registerMail();
    
            Mail::to($request->email)->send($mail)

;

my problem is how send $data1 data into to view as user name and password ?

@component('mail::message')
# Welcome SleAgro Agricultural Product Management System

you can loging to the system using following credetail .

User name :
<br> 
password : 

@component('mail::button', ['url' => 'http://127.0.0.1:8000/login'])
Login
@endcomponent

Thanks,<br>
{{ config('app.name') }}
@endcomponent

can you give me way to do it

CodePudding user response:

Try this code

at RegisterMail

    private $data;

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

    public function build()
    {
        return $this->markdown('emails.register',[ 'data' => $this->data])
               ->subject('Register SLeAgro Agricultural Product Distribution System');
    }

At controller

     $data1 = [
               'email' => $request->email,
               'password' => $code
            ];
    
     $mail = new RegisterMail($data1);
    
     Mail::to($request->email)->send($mail);

Last thing the blade, you can use $data variable like any variable in blade.

  • Related