-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModelWithTouch.php
37 lines (30 loc) · 1.06 KB
/
ModelWithTouch.php
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
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\TouchRelation;
class ModelWithTouch extends Model{
protected $observables = ['touched'];
/*
* extends from Illuminate\Database\Eloquent\Relations\Relation
*/
public static function touched($callback)
{
static::registerModelEvent('touched', $callback);
}
/**
* extends from Illuminate\Database\Eloquent\Concerns\HasRelationships
* can be done for all relations if necessary
*/
protected function newBelongsTo(\Illuminate\Database\Eloquent\Builder $query, \Illuminate\Database\Eloquent\Model $child, $foreignKey, $ownerKey, $relation)
{
//Log::info('will return a new TouchRelation');
return new BelongsToWithTouch($query, $child, $foreignKey, $ownerKey, $relation);
}
/**
* extends from Illuminate\Database\Eloquent\Concerns\HasEvents
* to make it public, so that the model can run it
*/
public function fireModelEvent($event, $halt = true){
return parent::fireModelEvent($event, $halt);
}
}