Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by whitelisting our website.

Laravel 5.1: Unsupported operand types (FatalErrorException in …)

Ok. When I am upgrading my application from Laravel 5.0 to 5.1 I get an falat error that this showing “Unsupported operand types”


What did I do on Laravel 5.0:

I add two array with in + operator, and that is the problem. So, I looking for solution and get this on Laracast

$item_list = array(”=>’–Select–‘) + Model::lists(‘name’, ‘id’);

what do I do on Laravel 5.1

this is a quick fix: just add another function at the end of the line ( and just before of the ; )  ->toArray()

so, here is the updated code

$item_list = array(”=>’–Select–‘) + Model::lists(‘name’, ‘id’)->toArray();


Why this: the reason for this update.

In 5.1, in Colleciton.php, it uses this:

return new static(Arr::pluck($this->items, $value, $key));

instead of this:

return array_pluck($this->items, $value, $key);

which, in turn does this:

return (Arr::pluck($this->items, $value, $key));

So it looks like the new behavior is to return a collection vs an array, thus the need to specify the toArray()


credit: @scottlaurent

2 thoughts on “Laravel 5.1: Unsupported operand types (FatalErrorException in …)

  1. I think this is one of the most important info for me. And i am glad redanig your article. But should remark on some general things, The web site style is great, the articles is really nice : D. Good job, cheers

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Wordpress Social Share Plugin powered by Ultimatelysocial