我有3个输入用于选择具有以下名称的文件:
docs['selfie']
docs['id_card']
docs['bank_card']
我想检查docs['selfie']
是否有文件返回yes
,否则是否返回no
。但总是返回no
功能:
public function Document(Request $request)
{
if ($request->hasFile("docs['selfie']")) {
return "yes";
}
else {
return "no";
}
}
和表格:
{{ html()->form('POST', route('frontend.user.send.document'))->class('form-horizontal')->Attribute('enctype','multipart/form-data')->open() }}
<div class="row">
<div class="col-md-12">
<div class="form-group row">
<label class="col-form-label col-lg-2">id card</label>
<div class="col-lg-10">
<div class="custom-file">
<input type="file" class="custom-file-input" id="National_Card" name="docs['id_Card']">
<label class="custom-file-label" for="docs">chose file</label>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group row">
<label class="col-form-label col-lg-2">bank card</label>
<div class="col-lg-10">
<div class="custom-file">
<input type="file" class="custom-file-input" id="Bank_card" name="docs['bank_card']">
<label class="custom-file-label" for="Bank_card">chose file</label>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group row">
<label class="col-form-label col-lg-2">selfie</label>
<div class="col-lg-8">
<div class="custom-file">
<input type="file" class="custom-file-input" id="Selfie" name="docs['selfie']">
<label class="custom-file-label" for="Selfie">chose file</label>
</div>
</div>
<div class="col-lg-2">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#selfie_modal">see example</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group mb-0 clearfix">
{{ form_submit("send docs" . ' ') }}
</div><!--form-group-->
</div><!--col-->
</div><!--row-->
{{ html()->form()->close() }}
答案 0 :(得分:1)
尝试
public function Document(Request $request)
{
if ($request->hasFile("docs.selfie")) {
return "yes";
}
else {
return "no";
}
}
检查请求数据
echo "<pre>";
print_r($request->all());
die;
答案 1 :(得分:1)
您不必在HTML名称中使用引号:
<input type="file" class="custom-file-input" id="Selfie" name="docs[selfie]">
// instead of name="docs['selfie']"
将名称的所有引号删除到方括号中,则可以简单地使用:
dump($request->hasFile('docs.selfie'));
它将起作用