How to Display Data in Yajra Datatables Laravel 7?



PHP Snippet 1:

<table class="table align-middle table-hover table-nowrap mb-0"
       id="table_id"
       role="grid"
       aria-describedby="example2_info"
       style="width:100%"
>
    <thead class="table-light">
        <tr>
            <th>#</th>
            <th>Name</th>
            <th>Email</th>
            <th>Job Position</th>
            <th>Phone</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody class="list form-check-all">
    </tbody>
</table>
...
<script>
    $(document).ready(function() {
        let dataTable = $('#table_id').DataTable({
            processing: true,
            serverSide: true,
            autoWidth: false,
            filter: false,
            bLengthChange: false,
            responsive: true,
            language: {
                processing: '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span>'
            },
            ajax: {
                url: "{{ url('/your route goes here') }}",
                dataType: "json",
                type: "GET",
                data: function(d) {
                    d.filter_val = $('.search').val(),
                    d.search = $('input[type="search"]').val()
                }
            },
            columns: [
                {
                    data: "DT_RowIndex",
                    width: "3%"
                }, {
                    data: "name"
                }, {
                    data: "email"
                }, {
                    data: "job_position"
                }, {
                    data: "phone"
                }, {
                    data: "action",
                    orderable: false,
                    searchable: false
                }
            ]
        });
    });
</script>