1
<?php
2

3
namespace Igaster\ModelEvents\Traits;
4

5

6
use Igaster\ModelEvents\LogModelEvent;
7

8
/**
9
 * Note: This trait is Optional
10
 * Add this trait to the User Model to enable querying logged events for for a user model
11
 */
12

13
trait UserLogsModelEvents
14
{
15

16 1
    public function modelEvents()
17
    {
18 1
        return $this->hasMany(LogModelEvent::class,'user_id');
19
    }
20

21 1
    public function getUserModelEvents($count = 0)
22
    {
23 1
        $query = $this->modelEvents()->orderBy('id', 'desc');
24 1
        if($count) {
25 1
            $query->limit($count);
26
        }
27 1
        return $query->get();
28
    }
29

30
}

Read our documentation on viewing source code .

Loading