将参数传递给laravel

时间:2016-11-03 10:40:24

标签: php jquery laravel email

我想将sql数据作为参数传递给邮件模板。 ' welcome.blade.php'是我的邮件模板。我创建了邮件文件' Remainder.php'现在我发现内部服务器错误' 。我想将用户数据传递给welcome.blade.php

在ajax中调用mail函数

  $.ajax({
          type: "GET",
            url: "testHello",
            data: {'id':user_id},
            dataType: 'JSON',
            success: function(data, textStatus, jqXHR){
               //alert(data);
        }
          });

路线

  Route::get('testHello','travelerHome@test');

控制器

public function test(Request $request)
{
    $request_data = $request->all();
   $id = $request_data['id'];  
   $to_email = 'sathurka.palpandi@aspiresys.com';
    Mail::to($to_email)->send(new Reminder);
    return response()->json($id);  
} 

Remailder.php

public function build()
{
    DB::enableQueryLog();

$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.approver_id',$approver_id)->groupby('travel_request.id')->get(); 
    return $this->from('sathurka.palpandi@aspiresys.com')
                ->view('email.welcome',['users'=>$users]);
}

welcome.blade.php

@foreach ($users as $user) 
     {{$user->traveler_name}}
     @endforeach

1 个答案:

答案 0 :(得分:0)

您的查询中似乎有一个未定义的变量($ approver_id)。 您的代码看起来没问题,我认为查询会引发内部服务器错误'。

如果您检查日志,则应该能够查明问题。