如何在Laravel 5.7的Mail函数中传递数组

时间:2019-02-16 09:03:36

标签: laravel function email

以下是我的邮件功能: 如何将数组传递给邮件功能?

public function mail(Request $request , $id) {

      $data=[
        'owner'=>MyRoom::where('id',$id)->get(),
        'data2'=>$request->all(),
      ];
      Mail::send('emails.mail' , $data, function($message) use ($data){
        $message->to($owner->created_by->email , $owner->created_by->name)
                ->subject('Room showing Request From OpenRoomList');
        $message->from('regmibipin13@gmail.com','OpenRoomList');
      });
      echo "Email Send check your inbox";
    }

1 个答案:

答案 0 :(得分:0)

首先,不要执行get会为您提供集合的操作,而是这样做:

'owner' => MyRoom::find($id);

resources/emails/mail.blade.php刀片文件中,您可以使用$owner$data2之类的blde语法直接使用{{ $owner->somecolumn }}{{ $data2['somefield'] }}变量