IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/resources/views/schools/employees/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/resources/views/schools/employees/imageupload.blade.php

@extends('schools.school_layout')
@section('content')
<div class="row clearfix">
    <div class="col-sm-12">
        <div class="card">
            <div class="header">
                <h2><strong>List Of Employees (For Image Upload)</strong></h2>
            </div>
            <div class="body table-responsive">
                <table class="table table-bordered table-striped table-hover dataTable js-basic-example">
                    <thead>
                        <tr>
                            <th>S. No.</th>
                            <th>Upload Photo</th>
                            <th>EC No.</th>
                            <th>Name</th>
                            <th>Department</th>
                            <th>Designation</th>
                            <!--<th>Admission No</th>-->
                        </tr>
                    </thead>
                    <tbody>
                        <?php $i = 1; ?>
                        @foreach($employees as $value)
                        <tr>
                            <th scope="row">{{$i}}</th>
                            <th>
                                <img style="border-radius: 60px; width: 100px;height: 100px; margin-top:10px;"  id="uploadPreview{{$value->idEmployee}}" name="image">
                                <input type="file"  name="photo" id="image{{$value->idEmployee}}" onchange="PreviewImage({{$value->idEmployee}});">
                                <div id="photoerror{{$value->idEmployee}}"></div>
                            </th>
                            <td>{{$value->enrollmentNo}}</td>
                            <td>{{$value->firstName}} {{$value->middleName}} {{$value->lastName}}</td>
                            <td>{{$value->department->departmentName or ''}}</td>
                            <td>{{$value->designation->designationName or ''}}</td>
                            <!--<td>{{$value->admissionNo}}</td>-->
                        </tr>
                        <?php $i++; ?>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@stop
@section('script')
<script>
function PreviewImage(key) {
    var oFReader = new FileReader();
    oFReader.readAsDataURL(document.getElementById("image"+key).files[0]);
    oFReader.onload = function (oFREvent) {
        document.getElementById("uploadPreview"+key).src = oFREvent.target.result;
    };
    
    
    var image = $('#image'+key)[0].files[0];
    var form = new FormData();
    form.append('idEmployee', key);
    form.append('photo', image);
    $.ajaxSetup({
        headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $.ajax({
        type:"POST",
        url: "{{url('/school/empimageupload') }}",
        data: form,
        dataType: 'json',
        cache: false,
        contentType: false,
        processData: false,
        success:function(data){
            if( data[Object.keys(data)[0]] === 'SUCCESS' ){   
                //True Case i.e. passed validation
                $('#photoerror'+ key).empty();
            //   window.location = "{{url('comprates')}}";
            }
            else {                  //False Case: With error msg
            $("#msg").html(data);   //$msg is the id of empty msg
            }

        },

        error: function(data){
            var errors = data.responseJSON.errors;
            $('#photoerror'+ key).empty();
           // if(errors['ratePerUnit']=== undefined){
                errorate = '<span class="help-block"><strong>'+errors['photo']+'</strong></span>';
                $('#photoerror'+ key).html( errorate );
         //   }
        }
    });
}
</script>
@stop

Copyright © 2021 - 2025 IMMREX7