public function read_data() { $query = DB::table('read_ebook')->leftJoin('users', 'read_ebook.reader_id', '=', 'users.id')->leftJoin('ebooks', 'read_ebook.ebook_id', '=', 'ebooks.id')->select('users.name', 'ebooks.title', 'read_ebook.read_at', 'read_ebook.ebook_id'); return Datatable::query($query)->addColumn('index', function () { return '#'; })->addColumn('name', function ($model) { return $model->name; })->addColumn('title', function ($model) { return '<a href="' . route('ilib.backend.ebook.show', ['ebook' => $model->ebook_id]) . '">' . $model->title . '</a>'; })->addColumn('read_at', function ($model) { return mb_date_mysql2vn($model->read_at); })->searchColumns('users.name', 'ebooks.title', 'read_ebook.read_at')->make(); }
/** * Danh sách Reader theo định dạng của Datatables. * * @return \Datatable JSON */ public function data() { /** @var \Minhbang\ILib\Reader $query */ $query = Reader::queryDefault()->allowedEbook()->withUser(); if (Request::has('search_form')) { $query = $query->searchWhereBetween('ebook_reader.expires_at', 'mb_date_vn2mysql'); } return Datatable::query($query)->addColumn('index', function (Reader $model) { return $model->user_id; })->addColumn('code', function (Reader $model) { return $model->code; })->addColumn('name', function (Reader $model) { return "{$model->user_name} <small class=\"text-navy\"><em> - {$model->user_username}</em></small>"; })->addColumn('ebook', function (Reader $model) { return $model->ebook_title; })->addColumn('expires', function (Reader $model) { // chuyển ngày định dạng VN, bỏ phần giây :00 ở cuối $expires_at = substr(mb_date_mysql2vn($model->expires_at), 0, -3); return Html::linkQuickUpdate($model->user_id, $expires_at, ['attr' => 'expires_at', 'title' => trans('ilib::reader.expires_at'), 'class' => 'w-md no-focus', 'placement' => 'left'], ['class' => 'a-expires_at'], route($this->route_prefix . 'backend.reader_ebook.quick_update', ['reader' => $model->user_id, 'ebook' => $model->ebook_id])); })->addColumn('actions', function (Reader $model) { return Html::tableActions($this->route_prefix . 'backend.reader_ebook', ['reader' => $model->user_id, 'ebook' => $model->ebook_id], trans('ilib::reader.allowed_title', ['reader' => "{$model->user_name} ({$model->user_username})", 'ebook' => $model->ebook_title]), trans('ilib::reader.allowed'), ['renderEdit' => false, 'renderShow' => false]); })->searchColumns('users.username', 'users.name')->make(); }