mercredi 28 septembre 2016

How do I display mysql data in datatables using Laravel?

I have a table payments. I would want to display the contents in datatables. I have tried to follow the http://ift.tt/1S0sDK7 to achieve this but I am not successful. I am using laravel 5. The latest version.

Kindly find my code below and possible direct me.

for the route:

<?php
use Yajra\Datatables\Datatables;
use DB;

Auth::routes();

Route::get('/home', 'HomeController@index');

Route::get('/payments', [
    'as'   => 'payments',
    'uses' => function () {
        $payments = App\payments::select([
'name','amount', 'trans_id', 'msisdn', 'time_paid', 
'account', 'organizationaccountbalance']);

      return Datatables::of($payments)->make();
    }

the view: payments.blade.php

@extends('layouts.master')

@section('content')
<table class="datatable">
    <thead>
      <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Amount</th>
        <th>Transaction ID</th>
        <th>Mobile Number</th>
        <th>Time Paid</th>
        <th>Account</th>
        <th>Organisation Account Balance</th>
      </tr>
    </thead>
    <tbody>
    </tbody>
  </table>
  <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="//cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
  <script>
    $(document).ready(function(){
      $('.datatable').DataTable({
            processing: true,
            serverSide: true,
            ajax: ''
        });
    });
  </script>
     @endsection
]);

Anytime I try to view /payments is get the error below:

FatalThrowableError in web.php line 23: Class 'App\payments' not found

    in web.php line 23
    at RouteServiceProvider->{closure}() in Route.php line 176
    at Route->runCallable() in Route.php line 147
    at Route->run(object(Request)) in Router.php line 642
    at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
    at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
     ......................

What am I doing wrong, anyone?

Thank you.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2dsetRf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire