dimanche 30 octobre 2016

Make Input file required based on database in laravel

I have a dynamic input file in laravel, input file will display based on data in database on select dropdown. here is my database loop_attachment table

here is the explanation by code i have.

ajax when select 2 dropdown which has id=groupid and id=lendertype:

$('#groupid').on('change', function(){
    $.post('', {type: 'loop_attachment', id: $('#groupid').val(), key: $('#lendertype').val()}, function(e){
        $('#image').html('');
        $('#image').html(e);
        });
    });
$('#lendertype').on('change', function(){
    $.post('', {type: 'loop_attachment', id: $('#groupid').val(), key: $('#lendertype').val()}, function(e){
        $('#image').html('');
        $('#image').html(e);
        });
    });

when select dropdown, input file will display in here :

<div class="row" id="image">
</div>

and here is my controller :

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;       
}

Currently there are no errors or issues. My question is, how to make input file become required if required column is 1 ? please help me with the code.

I hope my explanation easy to understand. Thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2dU00S9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire