0

I have an array to pass from controller to view.

$data['message'] = $data = $service->users_messages->get('me',$messageId, $optParamsGet2);
$data['mail'] = $mail;

while adding $data['mail'] = $mail, it showing the array_merge(): Argument #2 is not an array.

I need to render both $message and $mail in the view. How can i?

2
  • 1
    Where is your array_merge code Commented Oct 26, 2015 at 10:12
  • please provide your code. Commented Oct 26, 2015 at 10:13

1 Answer 1

1

Your Error

array_merge(): Argument #2 is not an array

Where it occurs

The line where you are generating the view for your mail:

E.g: view('greetings', $data);

or

Mail::send('greetings', $data, function ($message) {});

Why it occurs

When passing information to a view, $data should be an array with key/value pairs. Inside your view, you can then access each value using its corresponding key, such as <?php echo $key; ?>

Source: http://laravel.com/docs/5.1/views#passing-data-to-views

In your case, $data is NOT an array, hence the error.

How to Fix

Make sure your $data variable is an array when being passed to the above examples.

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

2 Comments

thanks @Mysteryos. I'm dealing with gmail-api and it provides me a pretty good well formed nested array
Can you update your question with the full code brief? It would help. Also an error trace dump as well.

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.