【问题标题】:Laravel 5.1 form - 'files' => trueLaravel 5.1 表单 - '文件' => true
【发布时间】:2017-01-13 15:08:49
【问题描述】:

我使用 Laravel HTML 创建表单但我有问题,所以在创建表单时我有:

{!! Form::open(['url'=>'vocuhers','files' => 'true','enctype'=>'multipart/form-data']) !!}

    @include('vouchers.form',['submitButtonText'=>'Click to Add New Vocuher'])

{!! Form::close() !!}

但是当我在浏览器中看到我的 HTML 表单时,只有:

<form method="POST" action="http://localhost:8888/vouchers" accept-charset="UTF-8">
   <input name="_token" type="hidden" value="dfgdfgdfgdfgdf">

那么在哪里

enctype="multipart/form-data"

允许我从表单上传文件?

为什么我没有得到这个 HTML 输出:

<form method="POST" action="https://bedbids.com/chats" accept-charset="UTF-8" enctype="multipart/form-data">
  <input name="_token" type="hidden" value="dsfdfgdfgdfgdfg">

这里到底有什么问题?

【问题讨论】:

  • 您是否在寻找正确的页面?你的urlvocuhers 而你的actionvouchers
  • 我解决了,这里没问题
  • 我的控制器有问题...那里是 vocuher.create 我有凭证.index ...感谢您的帮助

标签: php html forms laravel laravel-5.1


【解决方案1】:

改成这样:

{!! Form::attributes(['enctype'=>"multipart/form-data"])open(['url'=>'vocuhers']) !!}

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:
{!! Form::open(['url'=>'vocuhers','files' => 'true','enctype'=>'multipart/form-data']) !!}

改成

{!! Form::open(['url'=>'vocuhers','files' =>true,'enctype'=>'multipart/form-data']) !!}

正如马金森所说的

【讨论】:

    【解决方案3】:

    url 更改为route,如下所示。

    {{!! Form::open(['route'=>'vocuhers','class'=>'your_class','files'=>true]) !!}} 
    

    【讨论】:

    • 不,根本无法将新的 elemnet 添加到表单标签中......我也删除了 IlluminateHTML ,现在我只有 Laravel Collective
    【解决方案4】:

    您的语法错误。以下对我有用:

    {{Form::open(array('url' => 'your_url', 'method' => 'post', 'files' => true))}}
    

    【讨论】:

    • 我也尝试将 'class' 添加到表单中但不起作用:{{Form::open(array('url' => 'vouchers', 'class'=>'form-new' , 方法' => '发布', '文件' => true))}}
    猜你喜欢
    • 1970-01-01
    • 2016-12-10
    • 2016-03-11
    • 2016-10-02
    • 2017-06-06
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多