mirror of
https://github.com/flarum/core.git
synced 2025-08-11 02:44:04 +02:00
Use new Model extender
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Flags\Listener;
|
||||
|
||||
use Flarum\Event\ConfigureModelDates;
|
||||
use Flarum\User\User;
|
||||
|
||||
class AddFlagsApiDates
|
||||
{
|
||||
public function handle(ConfigureModelDates $event)
|
||||
{
|
||||
if ($event->isModel(User::class)) {
|
||||
$event->dates[] = 'read_flags_at';
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,12 +14,9 @@ use Flarum\Api\Event\WillGetData;
|
||||
use Flarum\Api\Event\WillSerializeData;
|
||||
use Flarum\Api\Serializer\PostSerializer;
|
||||
use Flarum\Event\GetApiRelationship;
|
||||
use Flarum\Event\GetModelRelationship;
|
||||
use Flarum\Flags\Api\Controller\CreateFlagController;
|
||||
use Flarum\Flags\Api\Serializer\FlagSerializer;
|
||||
use Flarum\Flags\Flag;
|
||||
use Flarum\Post\Event\Deleted;
|
||||
use Flarum\Post\Post;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
@@ -30,24 +27,12 @@ class AddPostFlagsRelationship
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']);
|
||||
$events->listen(Deleted::class, [$this, 'postWasDeleted']);
|
||||
$events->listen(GetApiRelationship::class, [$this, 'getApiRelationship']);
|
||||
$events->listen(WillGetData::class, [$this, 'includeFlagsRelationship']);
|
||||
$events->listen(WillSerializeData::class, [$this, 'prepareApiData']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GetModelRelationship $event
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany|null
|
||||
*/
|
||||
public function getModelRelationship(GetModelRelationship $event)
|
||||
{
|
||||
if ($event->isRelationship(Post::class, 'flags')) {
|
||||
return $event->model->hasMany(Flag::class, 'post_id');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Deleted $event
|
||||
*/
|
||||
|
Reference in New Issue
Block a user