<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class IsAdmin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if (Str::lower(session('admin.username')) == config('auth.username') &&
            session('admin.password') == config('auth.password'))
            return $next($request);

        return redirect()->route('admin.login')->with('error',"You don't have admin access.");
    }
}
