2020-04-12 00:26:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
|
|
|
|
class RedirectIfNotInitializedMiddleware
|
|
|
|
{
|
|
|
|
|
|
|
|
public $dontRedirect = ['initialize.index', 'initialize.store'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
|
|
|
if(!$this->shouldRedirect()) {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->initialized()) {
|
|
|
|
return redirect()->route('initialize.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldRedirect() {
|
2022-01-02 12:32:57 +01:00
|
|
|
return !request()->routeIs($this->dontRedirect) && auth()->check();
|
2020-04-12 00:26:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function initialized() {
|
2022-01-02 12:32:57 +01:00
|
|
|
return \App\Fee::count() > 0;
|
2020-04-12 00:26:44 +02:00
|
|
|
}
|
|
|
|
}
|