|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Distilleries\Contentful\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Distilleries\Contentful\Models\Base\ContentfulModel; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @property string $src_contentful_id |
|
9
|
|
|
* @property string $src_content_type |
|
10
|
|
|
* @property string $related_contentful_id |
|
11
|
|
|
* @property string $related_content_type |
|
12
|
|
|
* @property string $locale |
|
13
|
|
|
* @property string $country |
|
14
|
|
|
* @property integer $order |
|
15
|
|
|
* @property boolean $is_forbidden |
|
16
|
|
|
* @property \Carbon\Carbon $created_at |
|
17
|
|
|
* @property \Carbon\Carbon $updated_at |
|
18
|
|
|
*/ |
|
19
|
|
|
class EntriesRelationship extends ContentfulModel |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* The table associated with the model. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $table = 'entries_relationship'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The primary key for the model. |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $primaryKey = null; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Indicates if the IDs are auto-incrementing. |
|
37
|
|
|
* |
|
38
|
|
|
* @var boolean |
|
39
|
|
|
*/ |
|
40
|
|
|
public $incrementing = false; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The attributes that are mass assignable. |
|
44
|
|
|
* |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $fillable = [ |
|
48
|
|
|
'src_contentful_id', |
|
49
|
|
|
'src_content_type', |
|
50
|
|
|
'related_contentful_id', |
|
51
|
|
|
'related_content_type', |
|
52
|
|
|
'locale', |
|
53
|
|
|
'country', |
|
54
|
|
|
'order' |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* The attributes that should be cast to native types. |
|
59
|
|
|
* |
|
60
|
|
|
* @var array |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $casts = [ |
|
63
|
|
|
'order' => 'integer' |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get Contentful related entry. |
|
68
|
|
|
* |
|
69
|
|
|
* @return mixed |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getRelatedEntry() |
|
72
|
|
|
{ |
|
73
|
|
|
$localModel = rtrim(config('contentful.namespaces.model'), '\\') . '\\' . ucfirst($this->src_content_type); |
|
74
|
|
|
if (!class_exists($localModel)) { |
|
75
|
|
|
return null; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$model = (new $localModel); |
|
79
|
|
|
return $model |
|
80
|
|
|
->locale() |
|
81
|
|
|
->where($model->getKeyName(), '=', $this->src_contentful_id) |
|
82
|
|
|
->first(); |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|