如何在 laravel 邮件模板中发送数组变量?
How to send array variable in laravel mail template?
$carts= Cart::leftjoin('products', 'products.id', '=', 'carts.productid')
->leftjoin('sellers', 'sellers.id', '=', 'products.seller')
->select('products.*','carts.productid as productid','carts.userid as userid','carts.quantity as cartquantity','carts.subtotal as subtotal','carts.id as cartid','sellers.id as sellerid')->where('carts.userid',$_SESSION['salmonlightsuserid'])->get();
$data1 = array('carts'=>"$carts",'subtotal'=>"$subtotal",'totalquantity'=>"$totalquantity",'primaryaddress'=>"$primaryaddress");
$useremail=$_SESSION['salmonlightsuseremail'];
Mail::send('order-email-template',$data1, function($message) use($useremail){
$message->to($useremail)->subject
('Order');
$message->from('noreply@gamil.com');
});
It gives error in order-email-template.blade.php
Error is:- Invalid argument supplied for foreach()
@foreach($carts as $cartsnew)
你不需要双引号。
必须是 'carts' => $carts
.
$carts= Cart::leftjoin('products', 'products.id', '=', 'carts.productid')
->leftjoin('sellers', 'sellers.id', '=', 'products.seller')
->select('products.*','carts.productid as productid','carts.userid as userid','carts.quantity as cartquantity','carts.subtotal as subtotal','carts.id as cartid','sellers.id as sellerid')->where('carts.userid',$_SESSION['salmonlightsuserid'])->get();
$data1 = array('carts'=>"$carts",'subtotal'=>"$subtotal",'totalquantity'=>"$totalquantity",'primaryaddress'=>"$primaryaddress");
$useremail=$_SESSION['salmonlightsuseremail'];
Mail::send('order-email-template',$data1, function($message) use($useremail){
$message->to($useremail)->subject
('Order');
$message->from('noreply@gamil.com');
});
It gives error in order-email-template.blade.php Error is:- Invalid argument supplied for foreach() @foreach($carts as $cartsnew)
你不需要双引号。
必须是 'carts' => $carts
.