Completed
Pull Request — master (#114)
by Carlos
08:13 queued 04:58
created

src/Events/Event.php (1 issue)

Severity
1
<?php
2
3
/*
4
 * This file is part of the overtrue/laravel-follow
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Overtrue\LaravelFollow\Events;
13
14
use Illuminate\Broadcasting\InteractsWithSockets;
15
use Illuminate\Database\Eloquent\Model;
16
use Illuminate\Foundation\Events\Dispatchable;
17
use Illuminate\Queue\SerializesModels;
18
use Overtrue\LaravelFollow\Follow;
19
20
/**
21
 * Class Event.
22
 *
23
 * @author overtrue <[email protected]>
24
 */
25
class Event
26
{
27
    use Dispatchable;
28
    use InteractsWithSockets;
29
    use SerializesModels;
0 ignored issues
show
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by Overtrue\LaravelFollow\Events\Event: $id, $relations, $connection, $keyBy
Loading history...
30
31
    public $causer;
32
33
    public $relation;
34
35
    public $targets;
36
37
    public $class;
38
39
    /**
40
     * Event constructor.
41
     *
42
     * @param \Illuminate\Database\Eloquent\Model   $causer
43
     * @param \Overtrue\LaravelFollow\Events\string $relation
44
     * @param int|array                             $targets
45
     * @param \Overtrue\LaravelFollow\Events\string $class
46
     */
47
    public function __construct(Model $causer, string $relation, $targets, string $class)
48
    {
49
        $this->causer = $causer;
50
        $this->relation = $relation;
51
        $this->targets = $targets;
52
        $this->class = $class;
53
    }
54
55
    public function getRelationType()
56
    {
57
        return Follow::RELATION_TYPES[$this->relation];
58
    }
59
60
    public function getTargetsCollection()
61
    {
62
        return \forward_static_call([$this->targets->classname, 'find'], (array) $this->targets->ids);
63
    }
64
}
65