Uploaded image for project: 'PHP ORMs'
  1. PHP ORMs
  2. PHPORM-95

setAttribute does not accept key as integer

    • Type: Icon: Improvement Improvement
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • laravel-4.0.1
    • Affects Version/s: None
    • Component/s: Laravel
    • None

      https://github.com/mongodb/laravel-mongodb/issues/2639

      • Laravel-mongodb Version: 10.25.2
      • PHP Version: 8.2.11
      • Database Driver & Version: 4

      Description:

      When triyng to set a key of object as integer on update it throws a type error

      Steps to reproduce

      Set a key as integer on updateOrCreate
      Model::updateOrCreate(['_id' => 1], [ 1 => "value"])

      Actual behaviour

      It throws an error in MongoDB\Laravel\Eloquent\Model::216

      str_contains(): Argument #1 ($haystack) must be of type string, int given

      My sugesstion is change the code from

      if (str_contains($key, '.')) {

      to

      if (is_string($key) && str_contains($key, '.')) {

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            tom.selander@mongodb.com Tom Selander
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: