Monday, May 22, 2017

Why Laravel collection where() and whereIn() work differently on local and online environment

____ This is what show in tinker on Windows/Mac ___

>>> $a = collect([['a'=>1,'b'=>2],['a'=>'1','b'=>3]])
=> Illuminate\Support\Collection {#852
     all: [
       [
         "a" => 1,
         "b" => 2,
       ],
       [
         "a" => "1",
         "b" => 3,
       ],
     ],
   }

>>> $a->where('a',1)
=> Illuminate\Support\Collection {#877
     all: [
       [
         "a" => 1,
         "b" => 2,
       ],
       [
         "a" => "1",
         "b" => 3,
       ],
     ],
   }

>>> $a->whereIn('a',[1])
=> Illuminate\Support\Collection {#877
     all: [
       [
         "a" => 1,
         "b" => 2,
       ],
       [
         "a" => "1",
         "b" => 3,
       ],
     ],
   }

___ And This is what show on CentOS server

>>> $a = collect([['a'=>1,'b'=>2],['a'=>'1','b'=>3]])
=> Illuminate\Support\Collection {#1414
     all: [
       [
         "a" => 1,
         "b" => 2,
       ],
       [
         "a" => "1",
         "b" => 3,
       ],
     ],
   }

>>> $a->where('a',1)
=> Illuminate\Support\Collection {#1394
     all: [
       [
         "a" => 1,
         "b" => 2,
       ],
     ],
   }

>>> $a->whereIn('a',[1])
=> Illuminate\Support\Collection {#1388
     all: [
       [
         "a" => 1,
         "b" => 2,
       ],
     ],
   }

I had read Laravel collection doc, and it said, whereIn is same as whereInLoose(however whereInLoose was removed since 5.3), but on my server, whereIn work just like whereInStrict, when I not sure about what a numeric collection value type is, it always find nothing in a collection, then result in a fatal error. Does someone know what and why it happens , Thanks !



via Vow Sole

Advertisement