Move model observers onto attributes and tidy provider bindings.
Register observers with ObservedBy, bind the comment spam classifier, and keep AppServiceProvider focused on application wiring.
This commit is contained in:
@@ -4,9 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Observers\ArtworkAwardObserver;
|
||||
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[ObservedBy([ArtworkAwardObserver::class])]
|
||||
class ArtworkAward extends Model
|
||||
{
|
||||
protected $table = 'artwork_medals';
|
||||
@@ -21,21 +24,21 @@ class ArtworkAward extends Model
|
||||
|
||||
protected $casts = [
|
||||
'artwork_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'weight' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'weight' => 'integer',
|
||||
];
|
||||
|
||||
public const MEDALS = ['gold', 'silver', 'bronze'];
|
||||
|
||||
public const WEIGHTS = [
|
||||
'gold' => 5,
|
||||
'gold' => 5,
|
||||
'silver' => 3,
|
||||
'bronze' => 1,
|
||||
];
|
||||
|
||||
public static function weightFor(string $medal): int
|
||||
{
|
||||
return (int) config('artwork_medals.weights.' . $medal, self::WEIGHTS[$medal] ?? 0);
|
||||
return (int) config('artwork_medals.weights.'.$medal, self::WEIGHTS[$medal] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user