2017-01-20 83 views
0

我檢查了一些關於這個問題的問題,但仍然無法弄清楚。傳遞多個數據到電子郵件查看laravel 5.3

因此,這裏是我的控制器(我切斷了一些代碼來使問題短期):

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 protected]')->send(new NewRequestMail($user,$car,$time)); 

然後可郵寄:

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

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

現在,當我試圖在電子郵件數據獲取。查看此$car->status或嘗試獲取有關用戶的更多信息$user->street我在我的電子郵件中空白!我唯一得到的是$user->name。有一個更好的方法嗎 ?您的幫助將非常感激

回答

1

請使用使用參數

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); 

     }); 

所以在enquiry.blade.php(郵件文件夾中)laravel郵件功能文件,您可以訪問該對象的屬性

相關問題