-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEditionMiddleware.php
36 lines (30 loc) · 1023 Bytes
/
EditionMiddleware.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace App\Http\Middleware;
use App\Models\Edition;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class EditionMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$user = optional(Auth::user());
if (!Edition::current()) {
if ($user->hasRole('event organizer')) {
return redirect(route('moderator.editions.index'))
->dangerBanner("There is no edition. You should activate one to access this page.");
}
if ($user->is_crew) {
return redirect(route('dashboard'))
->dangerButton("There is no active edition. You can't access this page for now.");
}
}
return $next($request);
}
}