mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-25 16:24:35 +02:00
* feat: initial commit for feature management * style: fix StyleCI findings * fix(api): prohibit features of nonnull scope from API & fix(admin): wrong translate key * style: fix Static Analysis error
42 lines
977 B
PHP
42 lines
977 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Middleware\Models;
|
|
|
|
use App\Constants\FeatureConstants;
|
|
use Closure;
|
|
use CyrildeWit\EloquentViewable\Contracts\Viewable;
|
|
use Illuminate\Http\Request;
|
|
use Laravel\Pennant\Feature;
|
|
use RuntimeException;
|
|
|
|
/**
|
|
* Class RecordView.
|
|
*/
|
|
class RecordView
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param Request $request
|
|
* @param Closure(Request): mixed $next
|
|
* @param string $modelKey
|
|
* @return mixed
|
|
*/
|
|
public function handle(Request $request, Closure $next, string $modelKey): mixed
|
|
{
|
|
$model = $request->route($modelKey);
|
|
|
|
if (! $model instanceof Viewable) {
|
|
throw new RuntimeException('record_view should only be configured for viewable models');
|
|
}
|
|
|
|
if (Feature::active(FeatureConstants::ALLOW_VIEW_RECORDING)) {
|
|
views($model)->cooldown(now()->addMinutes(5))->record();
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|