From 6237f0a8327fafba51bdb594eae3c8b92c50eb96 Mon Sep 17 00:00:00 2001 From: Halim Date: Wed, 9 Nov 2016 23:42:26 -0500 Subject: [PATCH] Datatables work --- ...es3DataTable.php => ArticlesDataTable.php} | 14 ++++-- app/Http/Controllers/Article3Controller.php | 19 ------- app/Http/Controllers/Articles2Controller.php | 42 ---------------- app/Http/Controllers/ArticlesDTController.php | 50 +++++++++++++++++++ .../Controllers/ArticlesDTSController.php | 19 +++++++ .../{articles2 => datatables}/index.blade.php | 35 ++++++------- .../index2.blade.php} | 2 +- resources/views/layouts/app.blade.php | 2 + resources/views/layouts/navbar.blade.php | 2 +- routes/web.php | 13 +++-- 10 files changed, 112 insertions(+), 86 deletions(-) rename app/DataTables/{Articles3DataTable.php => ArticlesDataTable.php} (75%) delete mode 100644 app/Http/Controllers/Article3Controller.php delete mode 100644 app/Http/Controllers/Articles2Controller.php create mode 100644 app/Http/Controllers/ArticlesDTController.php create mode 100644 app/Http/Controllers/ArticlesDTSController.php rename resources/views/{articles2 => datatables}/index.blade.php (64%) rename resources/views/{articles2/index3.blade.php => datatables/index2.blade.php} (85%) diff --git a/app/DataTables/Articles3DataTable.php b/app/DataTables/ArticlesDataTable.php similarity index 75% rename from app/DataTables/Articles3DataTable.php rename to app/DataTables/ArticlesDataTable.php index b9dcb59..08cc9c7 100644 --- a/app/DataTables/Articles3DataTable.php +++ b/app/DataTables/ArticlesDataTable.php @@ -5,7 +5,7 @@ use App\Article; use Yajra\Datatables\Services\DataTable; -class Articles3DataTable extends DataTable +class ArticlesDataTable extends DataTable { /** * Display ajax response. @@ -18,6 +18,10 @@ public function ajax() ->eloquent($this->query()) ->addColumn('action', 'path.to.action.view') ->make(true); + + // $articles = Article::select(['id', 'title', 'body', 'created_at', 'updated_at']); + // return Datatables::of($articles)->editColumn('title', '{{ $title."-title" }}')->make(); + } /** @@ -27,9 +31,12 @@ public function ajax() */ public function query() { - $query = Article::query(); + //$query = Article::query(); + $query = Article::query()->select(['id', 'title', 'created_at', 'updated_at']); - return $this->applyScopes($query); + //return $this->applyScopes($query); + + return $query; } /** @@ -56,6 +63,7 @@ protected function getColumns() return [ 'id', // add your columns + 'title', 'created_at', 'updated_at', ]; diff --git a/app/Http/Controllers/Article3Controller.php b/app/Http/Controllers/Article3Controller.php deleted file mode 100644 index 2869671..0000000 --- a/app/Http/Controllers/Article3Controller.php +++ /dev/null @@ -1,19 +0,0 @@ -render('articles2.index3'); - - - } - -} diff --git a/app/Http/Controllers/Articles2Controller.php b/app/Http/Controllers/Articles2Controller.php deleted file mode 100644 index 96388dc..0000000 --- a/app/Http/Controllers/Articles2Controller.php +++ /dev/null @@ -1,42 +0,0 @@ -middleware('auth'); - } - - /** - * Display a listing of the resource. - */ - public function index() { - return view('articles2.index'); - } - - /** - * Process datatables ajax request. - */ - public function anyData() { - //return Datatables::of(\App\Article::query())->make(true); - - // $articles = Article::select(['id', 'title', 'body', 'created_at', 'updated_at']); - - // return Datatables::of($articles)->editColumn('title', '{{ $title."-title" }}')->make(); - - - return Datatables::of(Article::query())->make(); - - } - - -} diff --git a/app/Http/Controllers/ArticlesDTController.php b/app/Http/Controllers/ArticlesDTController.php new file mode 100644 index 0000000..463f703 --- /dev/null +++ b/app/Http/Controllers/ArticlesDTController.php @@ -0,0 +1,50 @@ +middleware('auth'); + } + + /** + * Display a listing of the resource. + */ + public function index() { + return view('datatables.index'); + } + + /** + * Process datatables ajax request. + */ + public function getBasicData() { + + $articles = Article::select(['id', 'title', 'body', 'created_at', 'updated_at']); + return Datatables::of($articles)->make(); + + //return Datatables::of(Article::query())->make(); + } + + /** + * Process datatables ajax request. + */ + public function AddEditRemoveColumn() { + + $articles = Article::select(['id', 'title', 'body', 'created_at', 'updated_at']); + + return Datatables::of($articles)->addColumn('action', 'edit')->make(); + + //return Datatables::of(Article::query())->make(); + } + + +} diff --git a/app/Http/Controllers/ArticlesDTSController.php b/app/Http/Controllers/ArticlesDTSController.php new file mode 100644 index 0000000..85ee6fd --- /dev/null +++ b/app/Http/Controllers/ArticlesDTSController.php @@ -0,0 +1,19 @@ +render('datatables.index2'); + + + } + +} diff --git a/resources/views/articles2/index.blade.php b/resources/views/datatables/index.blade.php similarity index 64% rename from resources/views/articles2/index.blade.php rename to resources/views/datatables/index.blade.php index db8b47a..99d0516 100644 --- a/resources/views/articles2/index.blade.php +++ b/resources/views/datatables/index.blade.php @@ -7,7 +7,7 @@

Articles List (Using Datatables)

- +
@@ -15,6 +15,7 @@ +
IdArticle Body Created At Updated At
@@ -31,27 +32,27 @@ @endpush \ No newline at end of file diff --git a/resources/views/articles2/index3.blade.php b/resources/views/datatables/index2.blade.php similarity index 85% rename from resources/views/articles2/index3.blade.php rename to resources/views/datatables/index2.blade.php index e6957a6..cd46dbd 100644 --- a/resources/views/articles2/index3.blade.php +++ b/resources/views/datatables/index2.blade.php @@ -4,7 +4,7 @@
-

Articles List (Using Datatables)

+

Articles List (Using Datatables as a Service Implementation)

{!! $dataTable->table() !!} diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 34e2988..0e74eb4 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -37,6 +37,8 @@ +