adhik13th's avatar

Showing data and Button at Laravel Datatables Yajra

I following this tutorial : https://stackoverflow.com/questions/47828331/how-to-route-in-laravel-datatables

its so simple , but i cant do it . after i set my controller and my route and view , its not showing data and and table. in the table i have a button like'action' how i can take this comand to this button ?

can you check my faulth query

 Route::get('user/show1', 'userController@show')->name('usershow1');
 Route::get('user/show1-dt', 'userController@indexDataTables')->name('usershow1dt');

controller

 public function show()
{
    
    $pemeliharaan = Pemeliharaan::with(['user','alat'])->where('status','harian')->get();
    
    return view('users.view_harian',['pemeliharaan' => $pemeliharaan]);
   
}
public function indexDataTables()
{
    $pemeliharaan = Pemeliharaan::query();

// return DataTables::eloquent($pemeliharaan)->toJson();
    return Datatables::of($pemeliharaan)->make(true);  
}

and i have a view like this . the page number,search and pagination is showing at view ,but this data not showing. can you correctted this view ?

 <div class="box-body table-responsive no-padding">
            <table class="table table-hover" id="table">
              <tbody><tr>
                <th>No</th>
                <th>Nama Alat</th>
                <th>status</th>
                <th>User Input</th>
                <th>Action</th>
                <th>Tanggal</th>
              </tr>
            
              {{--  @php ---> before i suing datatables my view like that
              $no=0;
              @endphp
              
              @foreach ($pemeliharaan as $i)
              <tr>
                <td>{{ ++$no }} </td>
                <td>{{ $i->alat->nama_alat}}</td>
                <td>{{ $i->status}}</td>
                <td>{{ $i->user->name}}</td>
                <td> <a href="/user/show/question/{{ $i->id }}" > <span class="label label-primary">Lihat Data</span> </a></td>
                <td>{{ $i->created_at}}</td>
              </tr>
              @endforeach  --}}
            </tbody></table>
        
          </div>
  .

  .

       @endsection
  @push('scripts')
  <script>
    $(function() {
        $('#table').DataTable({
            processing: true,
            serverSide: true,
            ajax: '{!! route('usershow1dt') !!}',
            columns: [
                
                { data: 'nama_alat', name: 'nama_alat'},
                { data: 'status', name: 'status'},
                { data: 'User Input', name: 'nama'},
                { data: 'Action', name: 'name'},//here my button 
                { data: 'Tanggal', name: 'created_at'},
                
            ],
        });
    })
</script>
      @endpush
0 likes
2 replies

Please or to participate in this conversation.