<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class EnsureInstalled
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next)
    {
        if (! file_exists(base_path('.env'))) {
            if (! $request->routeIs('install.index') && ! $request->routeIs('install.requirements') && ! $request->routeIs('install.store')) {
                return redirect()->route('install.index');
            }
        }
        return $next($request);
    }
}
