duandan4680 2017-04-27 00:57
浏览 46
已采纳

多上传laravel 5.4

I have a problem with storing the files I upload into my database table. This is my code of the view:

{!! Form::open(array('action' => 'ArticleController@store', 'method' => 'post' )) !!}

    <input type="hidden" name="user_id" value="1">
    <div class="form-group m-b-20">
        <label for="exampleInputEmail1">Titre</label>
        <input type="text" class="form-control" name='title' id="exampleInputEmail1" placeholder="Saisir titre">
    </div>


    <div class="form-group m-b-20">
        <label for="videourl">Video URL</label>
        <input type="text" name="video_link" class="form-control" id="videourl" placeholder="Saisir url..">
    </div>


    <div class="form-group m-b-20">
        <input type="file" name="files[]"  multiple="multiple" >
    </div>
   <div class="form-group m-b-20">
        <label>Description</label>
        <textarea class="summernote" name="description"></textarea>
    </div>

    <button type="submit" class="btn btn-success waves-effect waves-light">Enregistrer et publier</button>
    <button type="button" class="btn btn-danger waves-effect waves-light">Annuler</button>
{!! Form::close() !!}

and this is the code of my controller:

public function store(Request $request)
{
    Article::create($request->all());

    $article = New Article();
    $article->user_id = $request->get('user_id');
    $article->title = $request->get('title');
    $article->description = $request->get('description');
    $article->save();

    if($request->hasFile('files')):
        foreach ($request->file('files') as $file) :
            $path = '../articles/uploads';
            $titre = $file->getClientOriginalName();
            $file->move($path, $titre);
            $fichier = New Articlefile();
            $fichier->article_id = $article->id;
            $fichier->title = $title;
            $fichier->path = $path;
            $fichier->save();

        endforeach;

    endif;

    return redirect('articles');
}
  • 写回答

2条回答 默认 最新

  • dqc22586 2017-04-27 06:30
    关注

    Your opening line should allow the operation, so try

    {!! Form::open(array('action' => 'ArticleController@store', 'method' => 'post','files'=>'true' )) !!}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看