Laravel-datatables: Class Datatables does not exist

Created on 16 Oct 2017  路  2Comments  路  Source: yajra/laravel-datatables

Hello,

I'm trying to use serverside datable loading with yajra/databale.

This my composer.json :

    "require": {
        "php": ">=7.0.0",
        "baum/baum": "^1.1",
        "bestmomo/laravel5-artisan-language": "^0.1.2",
        "creativeorange/gravatar": "^1.0",
        "fideloper/proxy": "~3.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "maatwebsite/excel": "~2.1.0",
        "yajra/laravel-datatables": "^1.0"

php --version : PHP 7.0.18-1~dotdeb+8.1 (cli) ( NTS )

I add to config/app.php :

'providers' => [
    ...
    Yajra\DataTables\DataTablesServiceProvider::class,
],
'aliases' => [
    ...
    'DataTables' => Yajra\DataTables\Facades\DataTables::class,
]

And this is my controller file :

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use Datatables;
use App\Article;
use App\Base;

class Test extends Controller
{
  public function index()
    {
        return view('article.table');
    }

    public function data(Datatables $datatables)
    {
        $builder = Article::query()->select('id', 'base_id', 'gencode', 'size', 'colorLib');

        return $datatables->eloquent($builder)
                          ->editColumn('id', function ($user) {
                              return '<a>' . $user->id . '</a>';
                          })
                          //->addColumn('action', 'eloquent.tables.users-action')
                          ->rawColumns([1, 5])
                          ->make();
    }
}

After long hour google i tried all of this command :

  • $ php artisan vendor:publish --tag=datatables
  • $ composer dump-autoload
  • $ php artisan config:cache
  • $ php artisan cache:clear

but i still have this error :

ReflectionException
Class Datatables does not exist

Can anyone have a solution or know how to force to recognize the datatable class ?

i'am sorry for my english, i'm not very fluent.

Advance thanks guys ;)

documentation question

Most helpful comment

The problem is you are adding the alias as

'aliases' => [ ... 'DataTables' => Yajra\DataTables\Facades\DataTables::class, ]

But accessing the alias as
use Datatables;

which is wrong

use it like this
use DataTables;

All 2 comments

The problem is you are adding the alias as

'aliases' => [ ... 'DataTables' => Yajra\DataTables\Facades\DataTables::class, ]

But accessing the alias as
use Datatables;

which is wrong

use it like this
use DataTables;

There are breaking changes on v8. See upgrade guide for ref. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webwizard02 picture webwizard02  路  17Comments

jay-shah-rushiinfotech picture jay-shah-rushiinfotech  路  19Comments

mantrax314 picture mantrax314  路  15Comments

phainv picture phainv  路  16Comments

aliworkshop picture aliworkshop  路  14Comments