laravel - Save data of input files multiple -
i'm trying save list of files in post not save relationship.
i want save first post , add images inserted.
class savedata extends componentbase { public function onsubmitcontact() { /* * field: <input type="file" name="files[]" id='files' multiple="true"/> */ $files = input::file('files'); $modelfiles = new mymodetosave; $modelrelation = new modeltorelation; foreach($files $file): $modelfiles->data = $file; $modelfiles->save(); endforeach; $modelrelation->title = post('title'); /* more fields */ $modelrelation->save(); $modelrelation->files()->add($modelfiles); } }
tanks code cms october
not sure on exact use case, should work:
//pass model id, , find in function $model = modeltorelation::find(post('modelid')); //commit files relations $model->commitdeferred(post('_session_key')); foreach($model->files() $file) { //now can stuff file...or model }
Comments
Post a Comment