我一直在寻找解决方案几个小时。试图把enctype作为大多数建议,但仍然没有解决方案。
HTML
<form action="/backportal/knowledge/postlist" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<input type="text" class="form-control" placeholder="Title" name="title">
<label for="exampleInputEmail1">Short Description</label>
<input type="text" class="form-control" placeholder="Short description" name="short_desc">
<label for="exampleInputEmail1">Long Description</label>
<input type="text" class="form-control" placeholder="Short description" name="long_desc">
</div>
<div class="form-group">
<label for="exampleInputFile">Image</label>
<input type="file" class="form-control-file" name="image">
</div>
<br/>
<button type="submit" class="btn-primary">Submit</button>
</form>
控制器
public function postlist(Request $request){
if ($request->hasFile('image')) {
echo 'yes';
}else{
echo 'no';
}
}
答案 0 :(得分:0)
在Laravel 5.5中,你应该使用file:
public function postlist(Request $request){
if ($request->file('image')) {
echo 'yes';
}else{
echo 'no';
}
}