-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathmodel.blade.php
109 lines (94 loc) · 3.15 KB
/
model.blade.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
@php echo "<?php"
@endphp
namespace {{ $modelNameSpace }};
@php
$hasRoles = false;
if(count($relations) && count($relations['belongsToMany'])) {
$hasRoles = $relations['belongsToMany']->filter(function($belongsToMany) {
return $belongsToMany['related_table'] == 'roles';
})->count() > 0;
$relations['belongsToMany'] = $relations['belongsToMany']->reject(function($belongsToMany) {
return $belongsToMany['related_table'] == 'roles';
});
}
@endphp
use Illuminate\Database\Eloquent\Model;
@if($fillable)@foreach($fillable as $fillableColumn)
@if($fillableColumn === "created_by_admin_user_id")use Brackets\Craftable\Traits\CreatedByAdminUserTrait;
@elseif($fillableColumn === "updated_by_admin_user_id")use Brackets\Craftable\Traits\UpdatedByAdminUserTrait;
@endif
@endforeach
@endif
@if($hasSoftDelete)use Illuminate\Database\Eloquent\SoftDeletes;
@endif
@if (isset($relations['belongsToMany']) && count($relations['belongsToMany']))
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@endif
@if($hasRoles)use Spatie\Permission\Traits\HasRoles;
@endif
@if($translatable->count() > 0)use Brackets\Translatable\Traits\HasTranslations;
@endif
class {{ $modelBaseName }} extends Model
{
@if($hasSoftDelete)
use SoftDeletes;
@endif
@if($hasRoles)use HasRoles;
@endif
@if($translatable->count() > 0)use HasTranslations;
@endif
@if($fillable)@foreach($fillable as $fillableColumn)
@if($fillableColumn === "created_by_admin_user_id")use CreatedByAdminUserTrait;
@elseif($fillableColumn === "updated_by_admin_user_id") use UpdatedByAdminUserTrait;
@endif
@endforeach
@endif
@if (!is_null($tableName))protected $table = '{{ $tableName }}';
@endif
@if ($fillable)protected $fillable = [
@foreach($fillable as $f)
'{{ $f }}',
@endforeach
];
@endif
@if ($hidden && count($hidden) > 0)protected $hidden = [
@foreach($hidden as $h)
'{{ $h }}',
@endforeach
];
@endif
@if ($dates)protected $dates = [
@foreach($dates as $date)
'{{ $date }}',
@endforeach
];
@endif
@if ($translatable->count() > 0)// these attributes are translatable
public $translatable = [
@foreach($translatable as $translatableField)
'{{ $translatableField }}',
@endforeach
];
@endif
@if (!$timestamps)public $timestamps = false;
@endif
protected $appends = ['resource_url'];
/* ************************ ACCESSOR ************************* */
public function getResourceUrlAttribute()
{
return url('/admin/{{$resource}}/'.$this->getKey());
}
@if (count($relations))
/* ************************ RELATIONS ************************ */
@if (count($relations['belongsToMany']))
@foreach($relations['belongsToMany'] as $belongsToMany)/**
* Relation to {{ $belongsToMany['related_model_name_plural'] }}
*
* {{'@'}}return BelongsToMany
*/
public function {{ $belongsToMany['related_table'] }}() {
return $this->belongsToMany({{ $belongsToMany['related_model_class'] }}, '{{ $belongsToMany['relation_table'] }}', '{{ $belongsToMany['foreign_key'] }}', '{{ $belongsToMany['related_key'] }}');
}
@endforeach
@endif
@endif}