-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathEvent.php
More file actions
53 lines (47 loc) · 1.16 KB
/
Event.php
File metadata and controls
53 lines (47 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property Account $account
* @property Contact $contact
* @method static Builder forObject(Model $object, string $key = null)
*/
class Event extends Model
{
/**
* Get the account record associated with the event.
*
* @return BelongsTo
*/
public function account()
{
return $this->belongsTo('App\Account');
}
/**
* Get the contact record associated with the event.
*
* @return BelongsTo
*/
public function contact()
{
return $this->belongsTo('App\Contact');
}
/**
* Limits the results to a specific object.
*
* @param Builder $query
* @param Model $object
* @param string|null $key
* @return Builder
*/
public function scopeForObject(Builder $query, Model $object, string $key = null)
{
if (! $key) {
$key = strtolower(class_basename($object));
}
return $query->where('object_type', $key)
->where('object_id', $object->id);
}
}