src/Table.php
protected function getFieldsFromModels($models)
    {
        if (!$models->first()) {
            // No models, we can't add any columns.
            return [];
        }

        $model = $models->first();

        // These are the Laravel basic timestamp fields which we don't want to display, by default
        $timestamp_fields = ['created_at', 'updated_at', 'deleted_at'];
        // Grab the basic fields from the first model
        $fields = array_keys($model->toArray());
        // Remove the timestamp fields
        $fields = array_diff($fields, $timestamp_fields);
        if ($model->isSortable) {
            // Add the fields from the model's sortable array
            $fields = array_unique(array_merge($fields, $model->getSortable()));
        }

        return $fields;
    }
protected function getFieldsFromModels($models)
    {
        if (!$models->first()) {
            // No models, we can't add any columns.
            return [];
        }

        $model = $models->first();

        // These are the Laravel basic timestamp fields which we don't want to display, by default
        $timestamp_fields = ['created_at', 'updated_at', 'deleted_at'];
        // Grab the basic fields from the first model
        $fields = array_keys($model->toArray());
        // Remove the timestamp fields
        $fields = array_diff($fields, $timestamp_fields);
        if ($model->isSortable) {
            // Add the fields from the model's sortable array
            $fields = array_unique(array_merge($fields, $model->getSortable()));
        }

        return $fields;
    }
protected function getFieldsFromModels ( $ models ) { if ( ! $ models -> first ( ) ) { // No models, we can't add any columns. return [ ] ; } $ model = $ models -> first ( ) ; // These are the Laravel basic timestamp fields which we don't want to display, by default $ timestamp_fields = [ 'created_at' , 'updated_at' , 'deleted_at' ] ; // Grab the basic fields from the first model $ fields = array_keys ( $ model -> toArray ( ) ) ; // Remove the timestamp fields $ fields = array_diff ( $ fields , $ timestamp_fields ) ; if ( $ model -> isSortable ) { // Add the fields from the model's sortable array $ fields = array_unique ( array_merge ( $ fields , $ model -> getSortable ( ) ) ) ; } return $ fields ; }
Get fields based on a collection of models
@param $models
@return array
Get fields based on a collection of models