Sunday, March 4, 2018

Laravel: I’m retrieving two of the same model, it should be different. What is wrong with my find? - development

Laravel: I’m retrieving two of the same model, it should be different. What is wrong with my find?

I should get two unique models. I’m searching for (e.g.) ID 1 and 2 in my table, but my result gets me two times of ID 1.

It should be quite easy but my solution doesn’t work:

foreach($somearray as &$item){
    $item[1] = Sell::find($item[1])->with('user', 'sellImages', 'sellLinks')->first();
}

I have an array for example like that:

"items" => array:2 [▼
0 => array:2 [▼
  0 => 3
  1 => 1 //ID of Model
]
1 => array:2 [▼
  0 => 1
  1 => 2 //Id of Model
]

I don’t know why, after the foreach I get the wrong model in somearray[1][1]. It’s the same of somearray[0][1].

Why is it like that?



from Laravel Questions and Answers https://laravelquestions.com/laravel/laravel-im-retrieving-two-of-the-same-model-it-should-be-different-what-is-wrong-with-my-find/
via Lzo Media

No comments:

Post a Comment