Reputation: 682
i have created a modal for file uploading, this is a client request, so i need to do it this way, i have already this:
{{-- Single Take Photo modal --}}
<div class="modal modal-success fade" tabindex="-1" id="takephoto_modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="{{ __('voyager::generic.close') }}"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><i class="voyager-photo"></i> Tomar Foto</h4>
</div>
<div class="modal-footer">
<form action="#" id="takephoto_form" method="POST" enctype="multipart/form-data" method="post" files="true">
{{ csrf_field() }}
<input type='file' accept="image/x-png, image/jpeg" capture="camera"/>
<input type="submit" class="btn btn-success pull-right" value="Tomar Foto">
</form>
<button type="button" class="btn btn-default pull-right" data-dismiss="modal">{{ __('voyager::generic.cancel') }}</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Now, the js:
$('td').on('click', '.takephoto', function (e) {
$('#takephoto_form')[0].action = '{{ route('voyager.'.$dataType->slug.'.submitphoto', ['id' => '__id']) }}'.replace('__id', $(this).data('id'));
$('#takephoto_modal').modal('show');
});
And the function in controller:
// POST
public function submitPhoto(Request $request, $id)
{
$input = Input::all();
dd($input);
die();
}
Ok, everything is working, the js is taking the action to the function, and sending the id so i can update then the db, this is an edit function, this is what im getting, no files , Im using Laravel Voyager, its Laravel...so i can use any Laravel class.
Upvotes: 2
Views: 989
Reputation: 682
Already fixed by adding an id on html:
<input type='file' accept="image/x-png, image/jpeg" name="photo" id="photo" capture="camera"/>
Then you can do $request->hasFile('photo');
Upvotes: 1