<?php

namespace App\Http\Controllers\Guru;

use App\Http\Controllers\Controller;
use App\Models\Kelas;
use Illuminate\Http\Request;

class KelasController extends Controller
{
    public function index(Request $request)
    {
        $query = Kelas::query();

        // SEARCH
        if ($request->has('search')) {
            $search = $request->search;
            $query->where('nama_kelas', 'like', "%$search%")
                  ->orWhere('id_kelas', 'like', "%$search%");
        }

        // SHOW PER PAGE
        $perPage = $request->get('perPage', 10);

        $kelass = $query->paginate($perPage)->appends($request->all());

        return view('guru.kelas.index', compact('kelass'));
    }
}
