jonnybarnes.uk/app/Services/LikeService.php
Jonny Barnes 83d10e1a70
Refactor of micropub request handling
Trying to organise the code better. It now temporarily doesn’t support
update requests. Thought the spec defines them as SHOULD features and
not MUST features. So safe for now :)
2025-04-27 16:38:25 +01:00

31 lines
651 B
PHP

<?php
declare(strict_types=1);
namespace App\Services;
use App\Jobs\ProcessLike;
use App\Models\Like;
use Illuminate\Support\Arr;
class LikeService
{
/**
* Create a new Like.
*/
public function create(array $data): Like
{
if (Arr::get($data, 'properties.like-of.0')) {
// micropub request
$url = normalize_url(Arr::get($data, 'properties.like-of.0'));
}
if (Arr::get($data, 'like-of')) {
$url = normalize_url(Arr::get($data, 'like-of'));
}
$like = Like::create(['url' => $url]);
ProcessLike::dispatch($like);
return $like;
}
}