<?php

namespace App\Http\Controllers;

use App\Models\Classification;
use App\Models\Siswa;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Auth;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function __construct()
    {
        $user = Auth::user();
        if (isset($user->role)) {
            if ($user->role == "Siswa") {
                $siswa = Siswa::where("user_id", "=", $user->id)->first();
                if ($siswa) {
                    $user->biodata = $siswa;
                }

                $userClass = Classification::where("user_id", "=", $user->id)->first();
                if ($userClass) {
                    $user->kelas = $userClass->hasil_kelas;
                }
            }
        }

        view()->share("user", $user);
    }
}
