laravel-datatables icon indicating copy to clipboard operation
laravel-datatables copied to clipboard

Model timestamp, Exception Message: Trailing data

Open emiliosa opened this issue 7 years ago • 3 comments

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!

emiliosa avatar Oct 24 '18 21:10 emiliosa

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?

yajra avatar Oct 25 '18 01:10 yajra

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.

captura de pantalla de 2018-11-21 17-42-12

captura de pantalla de 2018-11-21 17-47-19

Insteand, using datatables:

captura de pantalla de 2018-11-21 17-44-59

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

captura de pantalla de 2018-11-21 17-52-02 captura de pantalla de 2018-11-21 17-56-04

Despite of Carbon exception, it throws when i call make() method from Datatable... Any ideas?

Thanks again for your time.

emiliosa avatar Nov 21 '18 21:11 emiliosa

+1

jhoanborges avatar Apr 05 '22 03:04 jhoanborges

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.

github-actions[bot] avatar Jul 12 '23 00:07 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Jul 19 '23 00:07 github-actions[bot]