2016-11-03 72 views
0

我想傳遞查詢值並獲取郵件模板中的值。我想以['users'=> $ users]傳遞數據。我發現內部服務器錯誤將查詢值傳遞給laravel中的郵件模板

controller 

$users = DB::table('travel_request') 
     ->join('department', 'travel_request.department_id', '=', 'department.id') 
     ->join('users', 'travel_request.approver_id', '=', 'users.id') 
     ->join('travel_purpose', 'travel_request.travel_purpose_id', '=', 'travel_purpose.id') 
     ->join('traveling_details', 'travel_request.id','=','traveling_details.travel_request_id') 
     ->join('country','country.id', '=', 'traveling_details.country_id') 
     ->join('travel_type','traveling_details.travel_type_id', '=', 'travel_type.id') 
     ->join('travel_request_status','travel_request.status_id', '=', 'travel_request_status.id') 
     ->select('travel_request.*', 'travel_request.id as travel_id','department.name as dept_name','users.firstname as approver_name','travel_purpose.purpose','country.name as country_name','traveling_details.from_date','traveling_details.to_date','travel_request_status.status','travel_type.type as travelType')->where('travel_request.id',$id)->get(); 

     Mail::Send('email.welcome', $users, function($message) use($users) { 
     $message->to('[email protected]', 'Travel Request')->subject 
     ('Testing Mail'); 
     $message->from('[email protected]','dummyname'); 
    }); 


welcome.blade.php 
@foreach ($users as $user) 
    {{$user->traveler_name}} 
@endforeach 
+0

檢查您的日誌,它說什麼? laravel 4的'app/storage/logs',laravel 5的'storage/logs'。 – aynber

回答

1

您可以使用如下

$data['users'] =$users; 
Mail::Send('email.welcome', $data, function($message) use ($data) { 
    $message->to('[email protected]', 'Travel Request')->subject 
     ('Testing Mail'); 
    $message->from('[email protected]','dummy text'); 
}); 


welcome.blade.php 
@foreach ($users as $user) 
    {{$user->traveler_name}} 
@endforeach 

這僅僅是通知。