MIF_E31211908/app/Http/Middleware/Authenticate.php

24 lines
575 B
PHP

<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
protected function redirectTo(Request $request): ?string
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthorized'], 401);
}
session()->flash('error', 'Maaf anda harus login terlebih dahulu!');
return route('login');
}
}