| |

PHP Advanced Datatable in Laravel >= 5.0


How to build your datatable class?

Create new class extend from \Phpdt\Ldt\Datatable and the use the following methods to build the query statement:

There are four static methods to build query in your datatable class:
  1. from
    • Required.
    • Static method.
    • return table name.
    • e.g.
      
          static function from(){
              return 'name_of_your_table_form_your_database';
          }
                      
  2. select
    • Optional.
    • Static method.
    • return string contains sql select statement .
    • all columns are used in creating datatable object in the action of your controller must be declared here.
    • If you don't want to use it, then the select statement will be '*'.
    • e.g.
      
              static function select(){
                  return 'mdl_user.*';
              }
                      
  3. joins
    • Optional.
    • Static method.
    • return array
    • is similar to the joins statement in laravel.
    • e.g.
      
              static function joins(){
                  return [
                      ['mdl_user_devices','mdl_user_devices.userid','=','mdl_user.id']
                  ];
              }
                      
  4. orderBy
    • Optional.
    • Static method.
    • return array
    • is similar to the orderBy statement in laravel.
    • e.g.
      
              static function orderBy(){
                  return [
                      ['id','asc'],
                      ['email','desc'],
                  ];
              }
                      


For example:

    class Test extends \Phpdt\Ldt\Datatable
    {

        const PRIMARY = 'id';
        static function from(){
            return 'mdl_user';
        }
        static function select(){
            return 'mdl_user.*';
        }
        static function joins(){
            return [
                ['mdl_user_devices','mdl_user_devices.userid','=','mdl_user.id']
            ];
        }
        static function orderBy(){
            return [
                ['id','asc'],
                ['email','desc'],
            ];
        }
    }
                


By: Mohammad Alaa Aldeen
Git: https://github.com/mhdalaaaldeen