<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Auth;
use App\Models\User;

class Profile
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        $user = User::with(['profile'])->where('id',auth()->user()->id)->first();
        if(!@$user->profile && ($user->ms_group_id == 2)){
            return redirect('profile-sekolah/lengkapi/'.encode_id($user->username));
        }
        return $next($request);
    }
}
