【问题标题】:Save data of input files multiple多次保存输入文件的数据
【发布时间】:2015-10-13 02:35:00
【问题描述】:

我正在尝试保存帖子中的文件列表,但它没有保存关系。

我想保存第一个帖子,然后添加插入的图片。

class SaveData extends ComponentBase {
    public function onSubmitContact() {
        /*
         * This field: <input type="file" name="files[]" id='files' multiple="true"/>
         */
        $files = Input::file('files');

        $modelFiles = new MyModeToSave;
        $modelRelation = new ModelToRelation;

        foreach($files as $file):
            $modelFiles->data = $file;
            $modelFiles->save();
        endforeach;

        $modelRelation->title = post('title');
        /* more fields */
        $modelRelation->save();

        $modelRelation->files()->add($modelFiles);
    }
}

坦克 代码这是 CMS OCTOBER

【问题讨论】:

    标签: laravel octobercms


    【解决方案1】:

    不确定您的确切用例,但这样的事情应该可以工作:

        //Pass your model id, and then find it in your function
        $model = ModelToRelation::find(post('modelID'));
        //commit all the files relations
        $model->commitDeferred(post('_session_key'));
    
        foreach($model->files() as $file) {
            //now you can do stuff with the file...or model
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多