Laravel-datatables: datatables warning ajax error 404 not found

Created on 28 Aug 2016  ·  10Comments  ·  Source: yajra/laravel-datatables

Summary of problem or feature request

I am new to laravel. I was able to run datatable using jquery plugin.
I would like the server side processing. I encountered error 404 the other day. Today I encountered
500 Internal Server Error. Call to undefined method Yajra\Datatables\Datatables:

  • Call to undefined method Yajra\Datatables\Datatables::eloquent() is present. Yesterday it was 404 file not found. Please help me fix error so that I can run server side processing. I am unable to see what causes this. Could it be that I am using sorting and search in my index?
  • I also tried to check the demo regarding left join however was unable to get the demo.
    An accession has categories and so need a join. **_How do you output data that comes from a join
    in the columns? Can you provide simple example for join used in server side processing?
  • How about if you also need a view and edit button in the columns, how do you place them?

Thank you for looking at this.

Code snippet of problem

image
here is route..
image
index.blade.php
image
service provider
image
alias
image

then accession

public function index(Request $request){

    $categories = Category::all();

    $query = Accession::select('*');

    //this is for links that will run query according to
    //category type

    if ($request->input('type')){

        switch ($request->input('type')){

            case 'Photo':

                $query->where('category_id', 2);

                break;

            case 'Field Notes':

                $query->where('category_id', 3);

                break;

            case 'Audio Recording':

                $query->where('category_id', 4);

                break;

            case 'Instrument':

                $query->where('category_id', 5);

                break;

            case 'Music Scores':

                $query->where('category_id', 6);

                break;

            case 'Video':


                $query->where('category_id', 7);

                break;

            case 'Vertical Files':

                $query->where('category_id', 8);

                break;

            default:

                $query->orderBy('id', 'asc')->get();
        }

        $accessions = $query->orderBy('id')->get();
        return view('accessions.index', compact('accessions', 'categories'));


    }

    //this is for search bar

    $search = $request->input('search'); //<-- we use global request to get the param of URI

    if($search){

        $accessions = Accession::where('groupcountry','LIKE','%'.$search.'%')
                    ->orWhere('description', 'LIKE', '%'.$search.'%')
                    ->orWhere('author', 'LIKE', '%'.$search.'%')
                    ->orWhere('accession_no','LIKE','%'.$search.'%')
                    ->orWhere('year','LIKE','%'.$search.'%')
                    ->paginate(10);

        return view('accessions.index', compact('accessions', 'categories'));
    }
    else{


        $accessions = Accession::orderBy('id', 'asc')->get();
        return view('accessions.index', compact('accessions', 'categories'));
    }


}

System details

  • Operating System Windows 10
  • PHP Version PHP 5.6.20
  • Laravel Version Laravel Framework version 5.2.45
  • Laravel-Datatables Version 6.0
question

Most helpful comment

404 Not Found is an intermittent issue of dataTables due to environment issue when using php artisan serve. Please use valet, homestead or wamp/xampp to avoid this issue.

All 10 comments

I changed the namespace to use Yajra\Datatables\Facades\Datatables;
Tables are now showing up hoewever received error.

image

the error is error 200

Try inspecting the ajax response to get a better view of the error. You may also need to double check that your columns and your js match your table structure. This is probably a js issue.

Thank you for the response. Yes I have checked the ajax response. JSON lint looks good. The error 200 disappeared. I checked the columns and js and match them with table structure. So far error now is

image
Will double check

image

image

image

404 Not Found is an intermittent issue of dataTables due to environment issue when using php artisan serve. Please use valet, homestead or wamp/xampp to avoid this issue.

@yajra . Yes. I am currently using xampp. Search continues

Route definition has been reviewed. Intermittent 404 but ajax returns data. I think I have to agree on environment issue.

Deployed the app live in heroku. 404 is gone. So this is confirmed environment issue. Closing this. @yajra Thank you for looking at the error. Your documentation also helped me with left join and view and edit button, Thank you.

The solution given above works just transfer your project to the HTDOCS of your XAMPPor www of your WAMPP or run it live

@marker17 just make your javascript and web.php as follows

 $(document).ready(function () {
    var table = $('#example').DataTable({
        dom: 'lBrtip',
        processing: true,
        serverSide: true,
        ajax: {
            'url':'{!!url("ajax/chapter/list")!!}',
            'type': 'POST',
            'headers': {
            'X-CSRF-TOKEN': '{{ csrf_token() }}'
            }
            },

        orderCellsTop: true,
        fixedHeader: true,

        "columns": [{
                data: 'DT_RowIndex',
                orderable: false,
                searchable: true
            },

            {data: 'stream_id'},
            {data: 'course_id'},
            {data:  'subject_id'},
            {data:  'chapter_name'},
            {data: 'status'},
            {data: 'edit_delete',orderable: false},
        ],
    });

});

And in web.php

Route::any('ajax/chapter/list','YourController@Method');

this code worked for me.

@marker17 just make your javascript and web.php as follows

 $(document).ready(function () {
    var table = $('#example').DataTable({
        dom: 'lBrtip',
        processing: true,
        serverSide: true,
        ajax: {
            'url':'{!!url("ajax/chapter/list")!!}',
            'type': 'POST',
            'headers': {
            'X-CSRF-TOKEN': '{{ csrf_token() }}'
            }
            },

        orderCellsTop: true,
        fixedHeader: true,

        "columns": [{
                data: 'DT_RowIndex',
                orderable: false,
                searchable: true
            },

            {data: 'stream_id'},
            {data: 'course_id'},
            {data:  'subject_id'},
            {data:  'chapter_name'},
            {data: 'status'},
            {data: 'edit_delete',orderable: false},
        ],
    });

});

And in web.php

Route::any('ajax/chapter/list','YourController@Method');

this code worked for me.

save my day

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nasirkhan picture nasirkhan  ·  3Comments

t0n1zz picture t0n1zz  ·  3Comments

Mopster picture Mopster  ·  3Comments

sangnguyenplus picture sangnguyenplus  ·  3Comments

ghost picture ghost  ·  3Comments