FleetCart/app/Http/Middleware/RedirectIfShouldNotCreateLicense.php

37 lines
704 B
PHP
Raw Normal View History

2023-06-11 12:14:03 +00:00
<?php
namespace FleetCart\Http\Middleware;
use Closure;
use FleetCart\License;
2023-12-03 14:07:47 +00:00
use Illuminate\Http\Request;
2023-06-11 12:14:03 +00:00
class RedirectIfShouldNotCreateLicense
{
private $license;
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
public function __construct(License $license)
{
$this->license = $license;
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
/**
* Handle an incoming request.
*
2023-12-03 14:07:47 +00:00
* @param Request $request
* @param Closure $next
*
2023-06-11 12:14:03 +00:00
* @return mixed
*/
2023-12-03 14:07:47 +00:00
public function handle($request, Closure $next): mixed
2023-06-11 12:14:03 +00:00
{
2023-12-03 14:07:47 +00:00
if ($this->license->valid() || !$this->license->shouldCreateLicense()) {
2023-06-11 12:14:03 +00:00
return redirect()->intended('/admin');
}
return $next($request);
}
}