我有这个代码工作正常
public function success(Request $request) { $paymentstatus=$request->input('status'); $transactionid=$request->input('txnid'); Ticket::where('transactionid',$transactionid)->update(['paymentstatus'=>$paymentstatus]); $ticketdata=Ticket::with('eventdetail')->where('transactionid',$transactionid)->first(); $venuename=$ticketdata->eventdetail->venuename; $eventname=$ticketdata->eventdetail->eventname; $eventdate=Carbon::parse($ticketdata->eventdetail->eventdate)->format('d M Y'); $myticketdata=array('ticketid'=>'200','class'=>'gold','no_of_persons'=>'10','fullname'=>'tommy dollar','email'=>'xya@gmail.com','mobile'=>'9874563210','transactionid'=>'alskdjflaskjdflakjd'); EmailController::sendemail($ticketdata->email,$myticketdata); return "success"; }
但我想发送使用下面给定的行获取的数组
$ticketdata=Ticket::with('eventdetail')->where('transactionid',$transactionid)->first();
所以在上面的函数我改变了这一行
EmailController::sendemail($ticketdata->email,$ticketdata);
但执行此代码后,我收到此错误
我知道这个错误是因为我没有将数组传递给此函数,但我无法纠正此代码.我也尝试将对象强制转换为数组,但这在这里没有用.
因为$ticketdata
是一个实例Illuminate\Database\Eloquent\Model
,您可以使用该toArray()
方法将其转换为数组:
$ticketdata = Ticket::with('eventdetail')
->where('transactionid', $transactionid)
->first()
->toArray();
http://laravel.com/api/5.1/Illuminate/Database/Eloquent/Model.html#method_toArray