composer.json
{ // "require": { "php": "^7.3", // "yajra/laravel-datatables-oracle": "^9.6" }, //}
{ // "require": { "php": "^7.3", // "yajra/laravel-datatables-oracle": "^9.6" }, //}
use App\AuditLog;use App\Http\Controllers\Controller;use Illuminate\Http\Request;use Yajra\DataTables\Facades\DataTables; class AuditLogsController extends Controller{ public function index(Request $request) { if ($request->ajax()) { $query = AuditLog::query()->select(sprintf('%s.*', (new AuditLog)->table)); $table = Datatables::of($query); $table->addColumn('placeholder', ' '); $table->addColumn('actions', ' '); $table->editColumn('actions', function ($row) { $viewGate = 'audit_log_show'; $editGate = 'audit_log_edit'; $deleteGate = 'audit_log_delete'; $crudRoutePart = 'audit-logs'; return view('partials.datatablesActions', compact( 'viewGate', 'editGate', 'deleteGate', 'crudRoutePart', 'row' )); }); $table->editColumn('id', function ($row) { return $row->id ? $row->id : ""; }); $table->editColumn('description', function ($row) { return $row->description ? $row->description : ""; }); $table->editColumn('subject_id', function ($row) { return $row->subject_id ? $row->subject_id : ""; }); $table->editColumn('subject_type', function ($row) { return $row->subject_type ? $row->subject_type : ""; }); $table->editColumn('user_id', function ($row) { return $row->user_id ? $row->user_id : ""; }); $table->editColumn('host', function ($row) { return $row->host ? $row->host : ""; }); $table->rawColumns(['actions', 'placeholder']); return $table->make(true); } return view('admin.auditLogs.index'); } //}
@extends('layouts.admin')@section('content') <div class="card"> <div class="card-header"> {{ trans('cruds.auditLog.title_singular') }} {{ trans('global.list') }} </div> <div class="card-body"> <table class=" table table-bordered table-striped table-hover ajaxTable datatable datatable-AuditLog"> <thead> <tr> <th width="10"> </th> <th> {{ trans('cruds.auditLog.fields.id') }} </th> <th> {{ trans('cruds.auditLog.fields.description') }} </th> <th> {{ trans('cruds.auditLog.fields.subject_id') }} </th> <th> {{ trans('cruds.auditLog.fields.subject_type') }} </th> <th> {{ trans('cruds.auditLog.fields.user_id') }} </th> <th> {{ trans('cruds.auditLog.fields.host') }} </th> <th> {{ trans('cruds.auditLog.fields.created_at') }} </th> <th> </th> </tr> </thead> </table> </div></div>@endsection@section('scripts')@parent<script> $(function () { let dtButtons = $.extend(true, [], $.fn.dataTable.defaults.buttons) let dtOverrideGlobals = { buttons: dtButtons, processing: true, serverSide: true, retrieve: true, aaSorting: [], ajax: "{{ route('admin.audit-logs.index') }}", columns: [ { data: 'placeholder', name: 'placeholder' },{ data: 'id', name: 'id' },{ data: 'description', name: 'description' },{ data: 'subject_id', name: 'subject_id' },{ data: 'subject_type', name: 'subject_type' },{ data: 'user_id', name: 'user_id' },{ data: 'host', name: 'host' },{ data: 'created_at', name: 'created_at' },{ data: 'actions', name: '{{ trans('global.actions') }}' } ], order: [[ 1, 'desc' ]], pageLength: 100, }; $('.datatable-AuditLog').DataTable(dtOverrideGlobals); $('a[data-toggle="tab"]').on('shown.bs.tab', function(e){ $($.fn.dataTable.tables(true)).DataTable() .columns.adjust(); });}); </script>@endsection