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

Advertisements

JavaScript/ jQuery Error ‘expected identifier, string or number’ in IE

IE sucks… and nothing to do coz. it’s windows default browser.

Hi this is my first post on JavaScript in my blog.. 🙂 I get a new error (JavaScript Error ‘expected identifier, string or number’ in IE) in JavaScript on IE when developing an application and got a solution on googling and post this here….

Sometimes we get this error and can’t seem to find a solution. It is worked on Firefox without no problem but on IE it throw an “expected identifier, string or number” error to the last line of the variable declaration. Take a look at the following codes that I was worked on..

1.  $(“#scrollin_project”).carousel({
2. direction: “vertical”,
3. loop: true,
4. dispItems: 3,
5. autoSlide: true,
6. animSpeed: 1500,
7. nextBtn: ‘<input id=”btn_down” type=”button” value=”” />’,
8. prevBtn: ‘<input id=”btn_up” type=”button” value=”” />’,
9. });

In IE, the error was reporting “expected identifier, string or number” on the last line of my (above) codes. Look at the line number 8, there is a comma (,) at the end of the code. And IE catch this as an JavaScript Error.

And Here is the error free codes

1.  $(“#scrollin_project”).carousel({
2. direction: “vertical”,
3. loop: true,
4. dispItems: 3,
5. autoSlide: true,
6. animSpeed: 1500,
7. nextBtn: ‘<input id=”btn_down” type=”button” value=”” />’,
8. prevBtn: ‘<input id=”btn_up” type=”button” value=”” />’
9. });

Now look at the end of the line number 8 of the above codes, it simple, I just delete the comma(,) and now there is no error on any browser.

Magento installation, validation(valid URL) problem/error

There is a validation problem arise when I try to install Magento in my localhost at the filed Base URL and showing message “Please enter a valid URL. Protocol is required(http://, https:// or ftp://)“.

Yes, everything is ok there, but to solve this problem you have to block/comment few lines of code

['validate-url', 'Please enter a valid URL. Protocol is required (http://, https:// or ftp://)', function (v) {
return Validation.get('IsEmpty').test(v) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
}],

To

/*  ['validate-url', 'Please enter a valid URL. Protocol is required (http://, https:// or ftp://)', function (v) {
return Validation.get('IsEmpty').test(v) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
}], */

at (line# 505) validation.js in YourSiteName\js\prototype\ folder. Just block/comment the above code and continue. 🙂