And for Datatables we will use the CDN script in the html header so that you don't have to bother downloading.
Now create a route with the get method to render html views,
Route::prefix('posts')->group(function () {
Route::get('/', 'PostsController@index')->name('posts.index');
Route::get('datatables_posts','PostsController@datatables')->name('datatables_posts');
});
In the controller, create 2 public functions, index and datatables, index to render views, while datatables to provide data accessed via the datatables script in the frontend.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\PostsModel;
use Yajra\Datatables\Datatables;
class PostsController extends Controller
{
public function index(){
return view("posts.index");
}
public function datatables(){
$posts = PostsModel::all();
return Datatables::of($posts)
->addColumn('action', function($posts){
return '<div class="form-group"><a class="btn btn-default" href="https://www.blogger.com/u/1/posts/edit/'.$posts-%3Eid.'">Edit</a></div><form action="'.route('posts.delete').'" method="POST"><input name="_token" type="hidden" value="'.csrf_token().'" /> <input name="post_id" type="hidden" value="'.$posts->id.'" /><button class="btn btn-default" type="submit">Delete</button></form>';
})->make(true);
}
}
And this is for viewing index requirements. Here datatables will be initialized and do queries on public function datatables.
@include('layouts.backend.header')
<div class="wrapper">
@include('layouts.backend.nav')
@include('layouts.backend.sidebar')
<!-- Content Wrapper. Contains page content -->
<br />
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<br />
<section class="content-header">
<h1>
Posts
<small>Index</small>
</h1>
</section>
<!-- Main content -->
<section class="content">
<div class="panel panel-default">
<div class="panel-body">
<a href="https://www.yourwebsite.com/{{ route('posts.add') }}">Add</a>
</div>
</div>
<table class="display table table-striped table-bordere" id="table_contact">
<thead>
<tr>
<th>Title</th>
<th>Created</th>
<th>Updated</th>
<th>Action</th>
</tr>
</thead>
</table>
</section>
<!-- /.content -->
</div>
@include('layouts.backend.credit')
</div>
<!-- ./wrapper -->
@include('admin.info.contact.script')
<script type="text/javascript">
$(document).ready( function () {
$('#table_contact').DataTable( {
ajax: "{{ route('datatables_posts') }}",
columns: [
{ data: 'post_title' },
{ data: 'created_at'},
{ data: 'updated_at'},
{ data: 'action'},
]
});
});
</script>
@include('layouts.backend.footer')
In that view you have included several layouts separately, for layout you can make your own custom, and don't forget to layout headers to include CDN JQuery and datatables to execute queries.
If everything has been done, and when accessed by http://localhost: 8000/posts displays the look below:
![]() |
| Datatables query result |
You have successfully used datatables, this tutorial is just as a basis for getting to know datatables, for more complete and detailed, you can visit the official website. And as a note, the results of the above data will appear if the intended table already has the data in question.


Awesome post. You Post is very informative. Thanks for Sharing.
ReplyDeleteWeb Designing training in Delhi
This is a lot to take in. Id rather hire the best web development company in the Philippines instead.
ReplyDeleteSuch a nice information i really like it very much seo services in uk
ReplyDeleteNice Blog ... Very Important Information Share By Author I Simply Says THanks TO You Keep Sharing THis TYpes OF INformaation In Future .. Feel Free So CHeck Our Services ALso :
ReplyDelete<a href="http://seoservicesislamabad.com/web-hosting-services-islamabad/click here</a>
Web Development Company in Lahore
ReplyDeleteCodeNinja.pk is digital products production studio, web development company in lahore web design seo digital marketing mobile app with creative mind innovation
Nice blog
ReplyDeleteThanks for such useful information really great information.
Hiteshi
Top Mobile App Development Company
Best Web Development Company
Buy canon printers and toner at best hp printer online store in USA
ReplyDeleteHi, This is a wonderfull blog it’s amazing and helpful, i want to see more blog to know more about other things like this because this blog gives me a lot of information, knowledge. And if you are interested or in need in IT Services like web development and other services free to visit us Azaza Biz Solution and give us a call.
ReplyDeleteGreat Post....
ReplyDeleteThanks for sharing this. This gives us good knowledge about how to build good website development in new technologies and also in new environment.
Hi, I read you blog it's amazing & helpful content. We are providing a lot services that are base on IT & development Service. Audacity24
ReplyDeleteThank you for sharing your thoughts and knowledge on this topic. This is really helpful and informative, as this gave me more insight to create more ideas and solutions for my plan. I would love to see more updates from you.
ReplyDeleteDallas digital marketing company
Nice information..Thanks for providing valuable information..
ReplyDeleteWebsite Design West Hollywood
SEO Company Santa Monica
Thanks for sharing such a great blog... I am impressed with you taking time to post a nice info.
ReplyDeleteClick here
Thank you for sharing, this is really helpful and help beginners to learn website development.
ReplyDeleteWhat a great online source of information about this topic. you have done great work. keep continue to sharing such kinds of post. Keep it up. Web Design and Development
ReplyDeleteGood information share with good presentation. Thank you
ReplyDeleteWeb Development India
ReplyDeleteGreetings! Very helpful advice in this particular article! It is the little changes that will make the greatest changes. Thanks for sharing!
web development agency