<?php

namespace App\Http\Middleware;

use Closure;
use App\Models\Company;
use Illuminate\Http\Request;

class CheckActiveCompany
{
  public function handle(Request $request, Closure $next)
  {
    $company = Company::active($request)->first();

    if (!$company) {
      return redirect('/admin/dashboard')->with('error', 'Silahkan pilih perusahaan yang aktif');
    }

    return $next($request);
  }
}
