php - Insert Collection to saveMany Eloquent -


i have collection filled models, how put these savemany method on relation? know must array, when $collection->toarray() no eloquent models anymore.

public function uploadandgetmodels($messageid, array $attachments) {     $models = new collection();     $attachments = new collection($attachments);     $attachments->each(function (uploadedfile $attachment) use ($messageid, $models) {         $identifier = $this->uploader->makeidentifier($attachment->getclientoriginalextension());         $this->uploader->uploadimage($attachment, "attachments/{$identifier}");         $model = new attachment(array('message_id' => $messageid, 'path' => $identifier));         $models->push($model);     });      return $models; } 

the result of $models collection full of attachment models.

if ($request->hasfile('attachments')) {     $attachments = $attachmentrepository->uploadandgetmodels($message->id, $request->file('attachments'));     $message->attachments()->savemany($attachments); } 

how able solve this?

the collection class has all() method returns items in collection array of models.

with in mind, should work...

$message->attachments()->savemany($attachments->all()); 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -