<?php

namespace App\Http\Controllers\Guru;

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

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

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

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

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

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