How to update a collection in laravel / eloquent

0

I'm using the laravel repository in my project. I created a Service to add some rules. In the upload method it is a reusable method to both save and refresh image. The save method works perfectly with the upload method. The update method does the upload process but does not save the data in the database. Qnd I get the image data in the upload method they arrive as follows:

Dpstheyhaveuploadedandreturnsthedatawiththenameoftherenamedfilereturnsthus:

Save method:

public function save($files, $id)
{
    $arr = $this->doUpload($files);
    foreach($arr as $entry)
    {
      $entry->projects_id = $id->id;
      $entry->save();
    }
    return;
}

Update method that nothing happens:

 public function updateImage($files, $id)
{
     $arr = $this->doUpload($files);
     foreach ($arr as $key) {
      $key = array(
        'filename' => $key->filename,
        'original_filename'=> $key->original_filename,
        'mime'=> $key->mime,
         );
     }
    return $this->uploadsRepository->update($arr, $id);

}

And I tried it too:

 public function updateImage($files, $id)
{
     $arr = $this->doUpload($files);

     foreach ($arr as $key) {
      $this->uploadsRepository->update($key, $id);
     }
    return ;

}

That returns the error:

Argument 1 passed to Prettus \ Repository \ Eloquent \ BaseRepository :: update () must be of the type array, object given, called in C: \ projects \ panel \ app \ Services \ ProjectService.php on line 45 and defined

    
asked by anonymous 16.05.2017 / 14:58

1 answer

1

I was able to do this:

Uploads::where('id', $id)->update($key);

But I found a good practice .. I do not know ..

What do you guys think?

This Uploads ::?

    
16.05.2017 / 16:24