【发布时间】:2017-03-13 04:27:58
【问题描述】:
我在 laravel 中有一个动态输入文件,输入文件将根据数据库中的数据在选择下拉菜单中显示。这是我的数据库
这是我的代码解释。
选择 id=groupid 和 id=lendertype 的 2 个下拉菜单时的 ajax:
$('#groupid').on('change', function(){
$.post('{{ URL::to('lender/dynamic') }}', {type: 'loop_attachment', id: $('#groupid').val(), key: $('#lendertype').val()}, function(e){
$('#image').html('');
$('#image').html(e);
});
});
$('#lendertype').on('change', function(){
$.post('{{ URL::to('lender/dynamic') }}', {type: 'loop_attachment', id: $('#groupid').val(), key: $('#lendertype').val()}, function(e){
$('#image').html('');
$('#image').html(e);
});
});
选择下拉菜单时,输入文件会显示在此处:
<div class="row" id="image">
</div>
这是我的控制器:
public function postDynamic(Request $request)
{
switch(Input::get('type')):
case 'loop_attachment':
$return = '';
foreach(Loop_attachment::where('groupid', Input::get('id'))->where('type2', Input::get('key'))->where('active', 1)->get() as $row)
$return .= "<div class='row'><div class='col-md-3'></div><div class='col-md-6'><center><div class='form-group'><div class='btn btn-primary'><span>Upload $row->doctype</span> <input type='file' style='margin-bottom:1px;' class='form-control upload' name='image[]' id='image-$row->doctype'></div></div></center></div><div class='col-md-3'></div></div>";
return $return;
break;
endswitch;
}
目前没有错误或问题。 我的问题是,如果 required 列为 1 ,如何使输入文件成为必需? 请帮我写代码。
我希望我的解释容易理解。提前致谢。
【问题讨论】:
-
先把外面的单引号改成双引号。这里
'{{ URL::to('lender/dynamic') }}' -
感谢您的回答,但这样做是为了什么?因为现在我所有的代码都已经可以工作了。如果 required column = 1,我需要的是代码如何制作必填字段
标签: php mysql ajax laravel laravel-5