laravel-datatables
laravel-datatables copied to clipboard
Model timestamp, Exception Message: Trailing data
Exception when setting default timestamp on Model
Vehicle class
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class Vehicle extends Model
{
const CREATED_AT = 'created_date';
const UPDATED_AT = 'modified_date';
protected $dates = ['created_date','modified_date'];
public function getCreatedDateAttribute()
{
return Carbon::parse($this->attributes['created_date'])->format('d/m/Y H:i:s');
}
public function getModifiedDateAttribute()
{
return Carbon::parse($this->attributes['modified_date'])->format('d/m/Y H:i:s');
}
}
Vehicle controller
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Vehicle;
use Illuminate\Http\Request;
use Yajra\Datatables\Datatables;
class VehiclesController extends Controller
{
public function datatableIndex()
{
return view('vehicles.datatables.index');
}
/**
* Process datatables ajax request.
*
* @return \Illuminate\Http\JsonResponse
*/
public function datatableData()
{
return Datatables::of(Vehicle::query())->make(true);
}
}
index.blade.php
@extends('layouts.app')
@section('title', 'Vehicles')
@push('javascript')
<script>
$(function() {
$('#vehicles-table').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('vehicles.datatable.data') !!}',
columns: [
{ data: 'created_date', name: 'created_date' },
{ data: 'modified_date', name: 'modified_date' },
]
});
});
</script>
@endpush
@section('content')
<table class="table table-bordered" id="vehicles-table">
<thead>
<tr>
<th>Created Date</th>
<th>Modified Date</th>
</tr>
</thead>
</table>
@endsection
Error
- PHP Version: 7.2
- Laravel Version: 5.7
- Laravel-Datatables Version: 8.9
Help, thanks!
I think the issue here is not related to dataTables but on your model and maybe carbon. Checking the web for some relevant issue and this seems to fit your error.
To make sure, try returning the query data first to see if it works?
Hi, sorry for so late response from me, ive been very busy with another proyect, like most of us.
Well, i have read that article already, and i dont have that problem outside yajra/laravel-datatable package.


Insteand, using datatables:

But! When i comment this lines on Vehicle model:
//const CREATED_AT; //const UPDATED_AT;

Despite of Carbon exception, it throws when i call make() method from Datatable... Any ideas?
Thanks again for your time.
+1
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been inactive for 7 days since being marked as stale.