Datatable with Laravel 7 Id route not working.

Datatable with Laravel 7 Id route not working.

Guyke187Guyke187 Posts: 5Questions: 3Answers: 0

Hello, I'm stumbling on a rather annoying problem.
When I say "give me all workdays from a specific timesheet_id" it gives me only the records when I hardcode the timesheet_id. Like here:

But when I try to use the id from the link it doesn't show me anything:


This is what I get back from returning the $id alone, I get no errors in console or network->fetch/xhr:

Not that I think it has anything to do with this but I'll post it as well:

<script>
        $(document).ready( function () {
            $('#myTable').DataTable({
                processing: true,
                serverSide: false,
                ajax: "{{ route( 'workdays.show', 'id') }}",
                order: ([2, 'des']),
                columns: [
                    { data: 'timesheet', name: 'timesheet', visible: true },
                    { data: 'id', name: 'id', visible: false },
                    { data: 'day', name: 'day', orderable: false, visible: true },
                    { data: 'date_sort', name: 'date_sort', visible: false,},
                    { data: 'date', name: 'date', orderData: [ 2 ] },
                    { data: 'day_type', name: 'day_type' },
                    { data: 'client', name: 'client' , visible: true},
                    { data: 'opportunity', name: 'opportunity' , visible: true},
                    { data: 'start', name: 'start' },
                    { data: 'end', name: 'end' },
                    { data: 'duration', name: 'duration' },
                    { data: 'pause', name: 'pause' },
                    { data: 'comment', name: 'comment', orderable: false},
                    { data: 'total', name: 'total'},
                    // { data: 'confirm', name: 'confirm'},
                    { data: 'actionButtons', name: 'actionButtons'},
                    { data: 'updated_at', name: 'updated_at'},
                ],
            });
        });
</script>

I hope someone can help me out with this. Thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin
    Answer ✓

    ajax: "{{ route( 'workdays.show', 'id') }}",

    What does that resolve to please?

    My guess is that the id isn't being added to the Ajax URL that is being generated.

    If you could post a link to a test case showing the issue, that would be useful.

    Thanks,
    Allan

  • Guyke187Guyke187 Posts: 5Questions: 3Answers: 0

    Because of what you said I started Googling a bit and found some post where someone passes a variable containing an ID from the URL, that didn't work for me but I managed to do it by retrieving the id from the URL directly. It works now. Much appreciated :)

    $(document).ready( function () {
            $('#myTable').DataTable({
                    processing: true,
                    serverSide: false,
                    ajax: '/consultant/timesheets/workdays/'+parseInt(window.location.href.split('/')[6].replace('#!', '')),
                    order: ([3, 'des']),
                    columns: [
                        { data: 'timesheet_id', name: 'timesheet_id', visible: false},
                        { data: 'id', name: 'id', visible: false },
                        { data: 'day', name: 'day', orderable: false, visible: true},
                        { data: 'date_sort', name: 'date_sort', visible: false},
                        { data: 'date', name: 'date', orderData: [ 3 ] },
                        { data: 'day_type', name: 'day_type' },
                        { data: 'client', name: 'client' , visible: true},
                        { data: 'opportunity', name: 'opportunity' , visible: true},
                        { data: 'start', name: 'start' },
                        { data: 'end', name: 'end' },
                        { data: 'duration', name: 'duration', visible: false },
                        { data: 'pause', name: 'pause' },
                        //{ data: 'comment', name: 'comment', orderable: false},
                        { data: 'total', name: 'total'},
                        // { data: 'confirm', name: 'confirm'},
                        { data: 'actionButtons', name: 'actionButtons'},
                        //{ data: 'updated_at', name: 'updated_at'},
                    ],
                });
            });
    
Sign In or Register to comment.