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:
Thank you for looking at this.
here is route..
index.blade.php
service provider
alias
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'));
}
}
I changed the namespace to use Yajra\Datatables\Facades\Datatables;
Tables are now showing up hoewever received error.
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
Will double check
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
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.