<?php
namespace App\Http\Controllers\Peserta;
use App\Facades\DataTable;
use App\Http\Controllers\Controller;
use App\Models\Pelatihan;
use App\Models\PelatihanPeserta;
use Illuminate\Http\Request;
use Inertia\Inertia;
class PelatihanController extends Controller
{
public function index()
{
$sort = str_replace(
['title', 'created_at'],
['title', 'created_at'],
request()->query('col')
);
$result = DataTable::query(Pelatihan::with(['pelatihan_pesertas'=>function($w){
$w->where('pelatihan_pesertas.user_id', auth()->user()->id)->orderBy('pelatihan_pesertas.created_at','DESC');
}])->withCount('pesertas')->whereHas('pesertas', function ($w) {
$w->where('pesertas.user_id', auth()->user()->id)->orderBy('pesertas.created_at','DESC');
}))
->searchable(['title', 'start_date', 'end_date'])
->applySort($sort)
->allowedSorts(['title', 'start_date', 'end_date', 'pesertas_count'])
->make()->toArray();
return Inertia::render('Peserta/Pelatihan/Index', [
'datatable' => $result
]);
}
public function show($id)
{
$pelatihan = Pelatihan::with(['pelatihan_pesertas'=>function($w){
$w->where('pelatihan_pesertas.user_id', auth()->user()->id)->orderBy('pelatihan_pesertas.created_at','DESC');
}])->withCount('pesertas')->whereHas('pesertas', function ($w) {
$w->where('pesertas.user_id', auth()->user()->id)->orderBy('pesertas.created_at','DESC');
})->with('instructor', 'pelatihan_materis', 'pelatihan_jadwals', 'syarat_pelatihans', 'province', 'regency')->findOrFail($id);
return Inertia::render('Peserta/Pelatihan/Detail', [ 'pelatihan' => $pelatihan]);
}
public function review($id, Request $request)
{
$pelatihanPeserta = PelatihanPeserta::findOrFail($id);
$pelatihanPeserta->update([
'review'=>$request->review
]);
return redirect(route('pelatihan.show',$pelatihanPeserta->pelatihan_id));
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]