Added NSFW compatibility

This commit is contained in:
2026-06-27 18:57:26 +02:00
parent 4a7c43f9e7
commit 76a1e62129
8 changed files with 74 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Models\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
class NsfwScope implements Scope
{
private function canNsfw(): bool
{
if( \Auth::guest() )
return false;
$user = \Auth::user();
return $user->nsfw_content === 1;
}
/**
* Apply the scope to a given Eloquent query builder.
*/
public function apply(Builder $builder, Model $model): void
{
if( !$this->canNsfw() )
$builder->where('nsfw', false );
}
}