简体   繁体   中英

passing multiple data to email view laravel 5.3

I have checked some questions about this question but still couldn't figure out.

So here is my controller ( I cut off some code to make the question short) :

public function hour(Request $request)
{
    $user = JWTAuth::parseToken()->authenticate();
    $user->phone = $request->phone;
    $user->city = $request->city;
    $user->street = $request->street;
    $user->save();

    $car = Car::find($request->id);
    $car->status = 'yes';
    $car->save();

    $time = new Reservation();
    $time->from_date = $from;
    $time->to_date =  $to;
    $Reservation_id = $time->id;
    $time->save();

    Mail::to('email@gmail.com')->send(new NewRequestMail($user,$car,$time));

then in Mailable:

public $car;
public $user;
public $time;

public function __construct($car,$time,$user)
{
    $this->car = $car;
    $this->time = $time;
    $this->user = $user;
}

Now when I try to fetch data in email.view liek this $car->status or try to get more info about the user $user->street I get blank in my email! the only thing I get is the $user->name . Is there a better way to do this ? you help will be really appreciated

please use laravel mail function with params

use Mail;


$to = '';
$from = '';
$subject = '';

Mail::send('email.enquiry', compact('user','car','time'), function ($message) use ($to,$from,$subject) {
            $message->from($from)
                    ->to($to)
                    ->subject($subject);

        });

So in enquiry.blade.php(inside email folder) file you can access the object properties

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM