yajra / laravel-datatables

jQuery DataTables API for Laravel
https://yajrabox.com/docs/laravel-datatables
MIT License
4.76k stars 858 forks source link

[SOLVED] Datatables functionalities doesn't work in production server (PHP 7.1 n Ubuntu 16.04.2) #1210

Closed agriirga closed 7 years ago

agriirga commented 7 years ago

i have implement yajra-datatables on my projects and works fine on my local development but when i'm deploy on my production server, all functionality in datatables doesn't work (such as : sort, search, and pagination). In my production server, Datatables display all data from database table (for example in my attachment : data from tools table, with 335 rows) .

My Sample Code

public function index(Request $request, Builder $htmlBuilder)
    {
        if($request->ajax()){
            $tools = Tool::with('machine','ct_owner','ct_location','status');
            //return Datatables::of($tools)->make('true');

            return Datatables::of($tools)

            // add column edit
            ->addColumn('edit', function($tool){
                return view ('datatable._edit',[
                    'model'    => $tool,
                    'edit_url' => route('tools.edit', $tool->id),
                ]);
            })
            //add column delete
            ->addColumn('delete', function($tool){
                return view ('datatable._delete',[
                    'model'    => $tool,
                    'delete_url' => route('tools.destroy', $tool->id),
                    'confirm_message' => 'Yakin mau menghapus ' . $tool->tools_serial_number . '?'
                ]);
            })
            ->make(true);
        }

        $html = $htmlBuilder
            ->addColumn(['data' => 'tools_serial_number', 'name' => 'tools_serial_number' , 'title' => 'Serial Number', 'orderable' => true,'searchable'=> true])
            ->addColumn(['data' => 'machine.machine_name', 'name' => 'machine.machine_name' , 'title' => 'Kategori Tool'])
            ->addColumn(['data' => 'ct_owner.central_tools_name', 'name' => 'ct_owner.central_tools_name' , 'title' => 'Central Tools Pemilik'])
            ->addColumn(['data' => 'ct_location.central_tools_name', 'name' => 'ct_location.central_tools_name' , 'title' => 'Posisi'])
            ->addColumn(['data' => 'merk', 'name' => 'merk' , 'title' => 'Merk'])
            ->addColumn(['data' => 'kondisi', 'name' => 'kondisi' , 'title' => 'Kondisi'])
            ->addColumn(['data' => 'status.display_name', 'name' => 'status.display_name' , 'title' => 'Status','searchable'=> true,])
            ->addColumn(['data'=>'edit' ,'name' =>'edit' , 'title' => '' ,'orderable' => false,'searchable'=> false, 'width' => '25px'])
            ->addColumn(['data'=>'delete' ,'name' =>'delete' , 'title' => '' ,'orderable' => false,'searchable'=> false, 'width' => '30px']);

        return view('tools.index')->with(compact('html'));
    }

System details

My Local Development : Laravel 5.3 PHP 7.0.9 Yajra Datatables 6.0 MySQL

Here's my productionserver environment : PHP 7.1.5 Ubuntu 16.04.2 Yajra Datatables 6.0 Laravel 5.3

Attachment

datatable problem server

last rows from my datatables: datatable problem server 2

yajra commented 7 years ago

Any error returned on you dev tools? Might be an issue on the server config where url params are encoded twice.

agriirga commented 7 years ago

there is no error returned by server (it returns 200 for all request), but when i'm trying to search on server the query params like this.

query-server

query result :

search-result

But on my local pc , it return query like this :

query-local

Did PHP 7.1.5 support for Datatables 6.0 ? Or maybe i should downgrade my PHP version ?

yajra commented 7 years ago

How about the inputs? I am using PHP 7.1 on the demo app so I guess it's not the problem.

Might be related to this: https://github.com/yajra/laravel-datatables/issues/1086

agriirga commented 7 years ago

inputs are empty....

inputs-query-server

i've tried to rewrite rule like above, but nothing changes ..

agriirga commented 7 years ago

it has been solved SIr,

We forgot to set cgi extension and mcrypt in our web server (nginx) cgi.fix_pathinfo=0; phpenmod mcrypt;

Thanks so much !!

sagadsalem commented 5 years ago

I am using php7.2 I set the cgi.fix_pathinfo=0 & php-mcrypt is not supported in v7.2 have the same problem all laravel datatable functionality is stopped without any error

sagadsalem commented 5 years ago

Ok i solve the problem it's all within nginx config so i will share both old and new nginx config old

server {
        listen 80;
        listen [::]:80 ipv6only=on default_server;
        root /var/www/example/public;
        index index.php index.html index.htm;

       try_files $uri $uri/ /index.php;

      location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
      }

}

new

server {
    listen 80;
    listen [::]:80;

    root /var/www/example/public;
    index index.php index.html index.htm;
    server_name cardeliver.net;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        proxy_read_timeout 180;
    }

    client_max_body_size 100000m;

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        proxy_read_timeout 180;
        fastcgi_read_timeout 180;
            }
}
lutfihp commented 2 years ago

For me, change on this line only make it works. note the ? (question mark) after index.php

    try_files $uri $uri/ /index.php?$query_string;