MIF_E31210400/app/Http/Controllers/RiwayatController.php

50 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use DataTables;
use GuzzleHttp\Client;
use Carbon\Carbon;
use App\Models\Riwayat;
class RiwayatController extends Controller
{
public function index(Request $request)
{
if ($request->ajax()) {
$data = Riwayat::select('*');
// Convert the Eloquent Collection to a regular PHP array
$data->each(function ($item, $key) {
$item->rowIndex = $key + 1;
});
return Datatables::of($data)
->addIndexColumn()
->addColumn('title-post', function($row){
$text = '
<p class="mb-0">' . $row->gejala . '</p>
';
return $text;
})
->addColumn('jenis_gejala', function($row){
return $row->gejala;
})
->rawColumns(['title-post', 'jenis_gejala'])
->make(true);
}
$data = [
'subtitle' => 'Riwayat'
];
return view('admin.app.content.riwayat.index', compact('data'));
}
}