Skip to content

Commit

Permalink
fix #888 (remove private events from api)
Browse files Browse the repository at this point in the history
  • Loading branch information
Apfelwurm committed Oct 28, 2024
1 parent 0100da1 commit 72d6989
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Event extends Model

protected static function boot()
{
// Remember There are is also an ApiGlobalScopesMiddleware used here

parent::boot();

$admin = false;
Expand Down
1 change: 1 addition & 0 deletions src/app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Kernel extends HttpKernel
'api' => [
'throttle:60000,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\ApiGlobalScopesMiddleware::class,
],

'userapi' => [
Expand Down
29 changes: 29 additions & 0 deletions src/app/Http/Middleware/ApiGlobalScopesMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Database\Eloquent\Builder;
use App\Event;


class ApiGlobalScopesMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{

Event::addGlobalScope('statusNotPrivate', function (Builder $builder) {
$builder->where('status', 'PUBLISHED');
});


return $next($request);
}
}

0 comments on commit 72d6989

Please sign in to comment.