init commit
This commit is contained in:
commit
c9d982669a
461 changed files with 30317 additions and 0 deletions
34
app/Http/Middleware/CheckPermission.php
Normal file
34
app/Http/Middleware/CheckPermission.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CheckPermission
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$permissions)
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
// Check if user has any of the required permissions
|
||||
foreach ($permissions as $permission) {
|
||||
if ($user->hasPermission($permission)) {
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
||||
// If no permissions match, return 403
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue