36 lines
783 B
PHP
36 lines
783 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Middleware;
|
||
|
|
|
||
|
|
use App\Models\Planner;
|
||
|
|
use Closure;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Support\Facades\Auth;
|
||
|
|
use Illuminate\Support\Facades\Hash;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
use Symfony\Component\HttpFoundation\Response;
|
||
|
|
|
||
|
|
class DemoMiddleware
|
||
|
|
{
|
||
|
|
public function handle(Request $request, Closure $next): Response
|
||
|
|
{
|
||
|
|
if (! is_mode_demo()) {
|
||
|
|
return $next($request);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Auth::check()) {
|
||
|
|
return $next($request);
|
||
|
|
}
|
||
|
|
|
||
|
|
$planner = Planner::create([
|
||
|
|
'name' => 'Demo User',
|
||
|
|
'email' => 'demo-' . Str::uuid() . '@demo.local',
|
||
|
|
'password' => Hash::make(Str::random(32)),
|
||
|
|
]);
|
||
|
|
|
||
|
|
Auth::login($planner);
|
||
|
|
|
||
|
|
return $next($request);
|
||
|
|
}
|
||
|
|
}
|