<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class ProfilMiddleware
{
    protected $exceptRoutes = [
        'profil.index'
    ];
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $user = auth()->user()->profil;
        if ($request->path()  === 'home') {
            return $next($request);
        }

        if($request->path() !== 'profil' && $user && ($user->tempat_lahir === NULL))

        {
            return redirect('profil');
        }

        return $next($request);
    }
}
