mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
35 lines
881 B
PHP
35 lines
881 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Resolvers\User;
|
|
|
|
use App\Contracts\Models\Likeable;
|
|
use App\GraphQL\Resolvers\BaseResolver;
|
|
use App\GraphQL\Schema\Mutations\Models\User\ToggleLikeMutation;
|
|
use App\Models\User\Like;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ToggleLikeResolver extends BaseResolver
|
|
{
|
|
final public const string ATTRIBUTE_ENTRY = 'entry';
|
|
final public const string ATTRIBUTE_PLAYLIST = 'playlist';
|
|
|
|
/**
|
|
* @param array<string, mixed> $args
|
|
*/
|
|
public function store(array $args): ?Like
|
|
{
|
|
$this->runMiddleware();
|
|
|
|
$validated = $this->validated($args, ToggleLikeMutation::class);
|
|
|
|
/** @var Model&Likeable $likeable */
|
|
$likeable = Arr::first($validated);
|
|
|
|
return $likeable->toggleLike(Auth::user());
|
|
}
|
|
}
|