Closed Tumi-D closed 4 years ago
@Tumi-D hi,
Can you provide some more information? The Invalid JSON response
means that your json reponsive is invalid. Can you share your controller and tableModel?
I switched to using livewire I honestly just didn't get the tutorial. Your package would have saved me an eternity tho. I will take my time to understand and use it on my next project. Thanks still !. But I hope a simple step by step guide would be made available in the not too distant future.
Hi, the docs don't include a tutorial but it is a good idea to create one. I will reopen and edit your question.
Hi @Tumi-D,
Checkout the tutorial here. Could you please check it out and let me know if anything is incorrect
Thanks a lot! Like that, you took the time to add the tutorial However, it still didn't work.
The things I feel will make the tutorial better 1) You use this command
php artisan make:table-model UsersTable --buttons --translations --route=users --query
To create the tableModel (UsersTable class ) yet when referencing in the UsersController Class which should be specified on the onset of the tutorial as a resource you simply call the class Users:: class instead of UsersTable::class
2) I don't know where this class is coming from \DataTable. My Intellisense suggests \SingleQuote\DataTables\DataTable If this is the actual class the is no static method called model in it. I tried instantiating a new class to call the model method it just works the same as me calling the static model.
3) A hint to use laravel/ui to generate the basic app scaffolding
4)In the Filling your table column a missing comma after the email
public $columns = [ 'id', 'name', 'email', 'created_at' ];
5)A little funny grammatical error showen I think you meant shown.
Back To My Code I kinda stopped reading at ### Filling the table model
<?php
namespace App\Http\Controllers;
use App\User; use Illuminate\Http\Request; use \SingleQuote\DataTables\DataTable as DataTable;
class UserController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
// $simpledatatable = new DataTable();
// $datatable = $simpledatatable->model(User::class);
// dd($datatable);
$datatable = \DataTable::model(User::class)->tableModel(\App\TableModels\UsersTable::class);
return view('users.index')->with(compact('datatable')); //⇐ pass the variable to the view
}
}
- **My tableModel**
<?php
namespace App\TableModels;
use Illuminate\Support\Facades\Date; use SingleQuote\DataTables\Controllers\ColumnBuilder; use SingleQuote\DataTables\Fields\Button; //button field use SingleQuote\DataTables\Fields\Date as FieldsDate;
/**
https://singlequote.github.io/Laravel-datatables/table-models */ class UsersTable extends ColumnBuilder {
// @var array public $tableClass = "table table-bordered";
/**
/**
/**
// /* // Alter the fields displayed by the resource. // // @return array // */ // public function fields(): array // { // return [ // // Button::make('id')->class('my-button-class')->route('users.show', 'id'), // // Button::make('id')->class('my-button-class')->route('users.edit', 'id'), // // Button::make('id')->class('my-button-class')->method('delete')->route('users.destroy', 'id'), // ]; // }
public function fields(): array { return [ FieldsDate::make('created_at')->format('d-m-Y') //dd-mm-YYYY ]; } }
- **My View**
@extends('layouts.app') @section('content')
@endsection
@push('js') {!! $datatable->script() !!} @endpush
**Unfortunately I probably missed something !** Final Output
![Screenshot (56)](https://user-images.githubusercontent.com/14878778/80759949-f83ec680-8aec-11ea-8595-f5ba924251d6.png)
Thank you for trying the tuturial.
1) the DataTable
as explained in the tutorial, requires 2 classes. First the model
requires an eloquent Model like the User
model. Second the actual tableModel you create using the command.
2) This is basic laravel. The \DataTable
is a facade you can use. Read the docs here instead of calling the whole class ($datatable = new \SingleQuote\DataTable\DataTable
) you can simply call the facade.
3) The packages doesn't rely on the ui or any Auth classes. Passing the User model which can be whatever the developer codes.
As for 4 and 5. Thanks :-)
I copied and tested your code. I don't see any errors popping up and it works like a charm. Can you provide the response the request returns?
Closed issue for inactivity
DataTables warning: table id=laravelDataTable5ea4749c0bd1f - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1