|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Larrock\Core\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Cache; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* \Larrock\Core\Models\Link. |
|
10
|
|
|
* |
|
11
|
|
|
* @property int $id |
|
12
|
|
|
* @property \Carbon\Carbon $created_at |
|
13
|
|
|
* @property \Carbon\Carbon $updated_at |
|
14
|
|
|
* @property mixed model_child |
|
15
|
|
|
* @property mixed model_parent |
|
16
|
|
|
* @property int id_child |
|
17
|
|
|
* @property int id_parent |
|
18
|
|
|
* @property float cost |
|
19
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Larrock\Core\Models\Link whereId($value) |
|
20
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Larrock\Core\Models\Link whereIdParent($value) |
|
21
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Larrock\Core\Models\Link whereIdChild($value) |
|
22
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Larrock\Core\Models\Link whereModelParent($value) |
|
23
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Larrock\Core\Models\Link whereModelChild($value) |
|
24
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Larrock\Core\Models\Link whereCost($value) |
|
25
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Larrock\Core\Models\Link whereCreatedAt($value) |
|
26
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Larrock\Core\Models\Link whereUpdatedAt($value) |
|
27
|
|
|
* @mixin \Eloquent |
|
28
|
|
|
*/ |
|
29
|
|
|
class Link extends Model |
|
30
|
|
|
{ |
|
31
|
|
|
protected $table = 'link'; |
|
32
|
|
|
|
|
33
|
|
|
protected $fillable = ['id_parent', 'id_child', 'model_parent', 'model_child', 'cost']; |
|
34
|
|
|
|
|
35
|
|
|
protected $casts = [ |
|
36
|
|
|
'cost' => 'float', |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
protected $appends = [ |
|
40
|
|
|
'cost', |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
public function getFullDataChild() |
|
44
|
|
|
{ |
|
45
|
|
|
$cache_key = sha1('getFullDataChild'.$this->model_child.$this->id_child); |
|
46
|
|
|
|
|
47
|
|
|
return Cache::rememberForever($cache_key, function () { |
|
48
|
|
|
$data = new $this->model_child; |
|
49
|
|
|
|
|
50
|
|
|
return $data->whereId($this->id_child)->first(); |
|
51
|
|
|
}); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|