kshitizmittal
7 months ago

Eloquent select() method

Posted 7 months ago by kshitizmittal

Controller Code :-

$attendanceReport = AttendanceReport::with('employeedetail')->select('date','emp_id','punch_in','punch_out');
        
return datatables($attendanceReport)->make(true);

Blade Code :-

<table id="datatables" class="display" style="width:100%">
                        <thead>
                            <tr>
                                <th>{{'Employee ID'}}</th>
                                <th>{{'Employee Name'}}</th>
                                <th>{{'Supervisor'}}</th>
                                <th>{{'Department Name'}}</th>
                                <th>{{'Date'}}</th>
                                <th>{{'In Time'}}</th>
                                <th>{{'Out Time'}}</th>
                                <th>{{'Status'}}</th>                          
                                <th>{{'Total Hours'}}</th>
                            </tr>
                        </thead>
                        <tbody>
                           
                        </tbody>
                    </table>
<script>
        $(document).ready( function () {
            $('#datatables').DataTable({
                "processing": true,
                "serverSide": true,
                "pageLength":100,
                "ajax": "{{ url('manish') }}",
                "ajax": { 
                    "url" : "{{ url('xyxxxxxxx') }}",
                    success : function ( json ) {
                        //Make your callback here.
                        alert("Done!");
                        console.log(json.data);
                    }  
                },
                "columns": [
                    { "data": "emp_id" },
                    { "data": "first_name" },
                    { "data": "date" },
                    { "data": "date" },
                    { "data": "date" },
                    { "data": "punch_in" },
                    { "data": "punch_out" },
                    { "data": "date" },
                    { "data": "date" }
                ]
            });
        });
    </script>

I want to fetch employee name in the table which comes from employee detail relation in model.

Please sign in or create an account to participate in this conversation.