/**
  * JSON data for seeding Users
  * @return \Illuminate\Http\JsonResponse
  * @throws \Exception
  */
 public function getUsers()
 {
     return Datatable::collection(User::all())->showColumns('name', 'ip_address')->addColumn('logged_in_at', function ($model) {
         return $model->logged_in_at->diffForHumans();
     })->addColumn('logged_out_at', function ($model) {
         return $model->logged_out_at->diffForHumans();
     })->addColumn('', function ($model) {
         return get_ops('user', $model->id);
     })->searchColumns('name', 'ip_address')->orderColumns('name', 'logged_in_at', 'logged_out_at')->make();
 }
 /**
  * Display ajax response.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function ajax()
 {
     $model = $this->getModelName();
     $datatables = $this->datatables->eloquent($this->query());
     foreach ($this->pluck_columns as $key => $value) {
         $datatables = $datatables->editColumn($key, function ($model) use($value) {
             return $model->{$value}[0]->{$value}[1];
         });
     }
     foreach ($this->image_columns as $image_column) {
         $datatables = $datatables->editColumn($image_column, function ($model) use($image_column) {
             return "<a target='_blank' href='{$model->{$image_column}}'>\n                            <img style='max-height:50px' class='img-responsive' src='{$model->{$image_column}}'/>\n                        </a>";
         });
     }
     if ($this->ops === true) {
         $datatables = $datatables->addColumn('ops', function ($data) use($model) {
             return get_ops($model, $data->id);
         });
     }
     return $datatables->make(true);
 }
 /**
  * Render nodes for nested sets
  *
  * @param $node
  * @param $resource
  * @return string
  */
 function renderNode($node, $resource)
 {
     $id = 'data-id="' . $node->id . '"';
     $list = 'class="dd-list"';
     $class = 'class="dd-item"';
     $handle = 'class="dd-handle"';
     $title = '<span class="ol-buttons"> ' . get_ops($resource, $node->id, 'inline') . '</span>';
     $title .= '<div ' . $handle . '>' . $node->title . '</div>';
     if ($node->isLeaf()) {
         return '<li ' . $class . ' ' . $id . '>' . $title . '</li>';
     } else {
         $html = '<li ' . $class . ' ' . $id . '>' . $title;
         $html .= '<ol ' . $list . '>';
         foreach ($node->children as $child) {
             $html .= renderNode($child, $resource);
         }
         $html .= '</ol>';
         $html .= '</li>';
     }
     return $html;
 }
 /**
  * JSON data for seeding Datatable
  *
  * @return mixed
  */
 public function getDatatable()
 {
     $language = Session::get('current_lang');
     return Datatable::collection($language->articles)->showColumns('title', 'read')->addColumn('category_id', function ($model) {
         return $model->category->title;
     })->addColumn('published_at', function ($model) {
         return $model->published_at;
     })->addColumn('updated_at', function ($model) {
         return $model->updated_at->diffForHumans();
     })->addColumn('', function ($model) {
         return get_ops('article', $model->id);
     })->searchColumns('title')->orderColumns('title', 'category_id', 'published_at', 'read')->make();
 }
 /**
  * JSON data for seeding Datatable
  *
  * @return mixed
  */
 public function getDatatable()
 {
     return Datatable::collection(Language::all())->showColumns('title', 'code')->addColumn('updated_at', function ($model) {
         return $model->updated_at->diffForHumans();
     })->addColumn('', function ($model) {
         return get_ops('language', $model->id);
     })->searchColumns('title')->orderColumns('title', 'code')->make();
 }
 /**
  * Display ajax response.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function ajax()
 {
     $model = $this->getModelName();
     $datatables = $this->datatables->eloquent($this->query());
     foreach ($this->image_columns as $image_column) {
         $datatables = $datatables->editColumn($image_column, function ($model) use($image_column) {
             return "<a target='_blank' href='{$model->{$image_column}}'>\n                            <img style='max-height:50px'\n                                 class='img-responsive'\n                                 src='" . asset($model->{$image_column}) . "'\n                             />\n                        </a>";
         });
     }
     foreach ($this->boolean_columns as $boolean_column) {
         $datatables = $datatables->editColumn($boolean_column, function ($model) use($boolean_column) {
             return $model->{$boolean_column} == true ? trans("admin.fields.yes") : trans("admin.fields.no");
         });
     }
     foreach ($this->count_columns as $count_column) {
         $datatables = $datatables->editColumn($count_column, function ($model) use($count_column) {
             return count($model->{$count_column}) ? $model->{$count_column}->count() : 0;
         });
     }
     if ($this->ops === true) {
         $datatables = $datatables->addColumn('ops', function ($data) use($model) {
             return get_ops($model, $data->id);
         });
     }
     return $datatables->make(true);
 }
 /**
  * @param        $result
  *
  * @param string $model
  *
  * @return mixed
  */
 protected function pushOps($result, $model = "")
 {
     if ($this->ops === true) {
         if (empty($model)) {
             $this->pushColumns($result, ['data' => 'ops', 'name' => 'ops', 'title' => trans('admin.ops.name')], false);
         } else {
             $result = $result->addColumn('ops', function ($data) use($model) {
                 return get_ops($model, $data->id);
             });
         }
     }
     return $result;
 }