4

I have this code which works fine

 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'=>'[email protected]','mobile'=>'9874563210','transactionid'=>'alskdjflaskjdflakjd');

   EmailController::sendemail($ticketdata->email,$myticketdata);

    return "success";
}

But I want to send array which is fetched by using below given line

$ticketdata=Ticket::with('eventdetail')->where('transactionid',$transactionid)->first();

So in above function i changed this line to

EmailController::sendemail($ticketdata->email,$ticketdata);

But after executing this code, I get this error enter image description here

I know this error is because i am not passing array to this function, but I am unable to rectify this code. I also tried to typecast object to array but that did't worked here.

3 Answers 3

6

Because $ticketdata is an instance of Illuminate\Database\Eloquent\Model, you can use the toArray() method to convert it to an array:

$ticketdata = Ticket::with('eventdetail')
    ->where('transactionid', $transactionid)
    ->first()
    ->toArray();

http://laravel.com/api/5.1/Illuminate/Database/Eloquent/Model.html#method_toArray

Sign up to request clarification or add additional context in comments.

Comments

0
 $status = \Mail::send('emails.templete_name', ['ticketdata' => $ticketdata, 'somethingelse'=> 'somethingelse'], function($message) use ($ticketdata)
            {
                $message->to($ticketdata->email, 'text')->subject('text');
            });

2 Comments

This doesn't answer the question. The code to send emails is behind EmailController::sendemail(). The parameterlist of this method requires the second parameter to be of type array. The OP asked for a way to convert his model to an array.
the error displayed in the email, should that the error is in the calling for the Mail:send not the EmailController::sendmail() . most probably he is using it in inside the sendmail()
0

Try this to have your data in array:

$ticketdata=Ticket::with('eventdetail')->where('transactionid',$transactionid)->first()->toArray();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.