1 | <?php |
||
49 | class Form extends Model |
||
50 | { |
||
51 | use HasSlug; |
||
52 | use ValidatingTrait; |
||
53 | use HasTranslations; |
||
54 | use CacheableEloquent; |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | protected $fillable = [ |
||
60 | 'entity_id', |
||
61 | 'entity_type', |
||
62 | 'slug', |
||
63 | 'name', |
||
64 | 'description', |
||
65 | 'content', |
||
66 | 'actions', |
||
67 | 'submission', |
||
68 | 'is_active', |
||
69 | 'is_public', |
||
70 | ]; |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | protected $casts = [ |
||
76 | 'entity_id' => 'integer', |
||
77 | 'entity_type' => 'string', |
||
78 | 'slug' => 'string', |
||
79 | 'name' => 'string', |
||
80 | 'description' => 'string', |
||
81 | 'content' => 'json', |
||
82 | 'actions' => 'json', |
||
83 | 'submission' => 'json', |
||
84 | 'is_active' => 'boolean', |
||
85 | 'is_public' => 'boolean', |
||
86 | 'deleted_at' => 'datetime', |
||
87 | ]; |
||
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | protected $observables = [ |
||
93 | 'validating', |
||
94 | 'validated', |
||
95 | ]; |
||
96 | |||
97 | /** |
||
98 | * The attributes that are translatable. |
||
99 | * |
||
100 | * @var array |
||
101 | */ |
||
102 | public $translatable = [ |
||
103 | 'name', |
||
104 | 'description', |
||
105 | ]; |
||
106 | |||
107 | /** |
||
108 | * The default rules that the model will validate against. |
||
109 | * |
||
110 | * @var array |
||
111 | */ |
||
112 | protected $rules = [ |
||
113 | 'entity_id' => 'nullable|integer', |
||
114 | 'entity_type' => 'nullable|string|strip_tags|max:150', |
||
115 | 'slug' => 'required|string|strip_tags|max:150', |
||
116 | 'name' => 'required|string|strip_tags|max:150', |
||
117 | 'description' => 'nullable|string|max:10000', |
||
118 | 'content' => 'required|array', |
||
119 | 'actions' => 'nullable|array', |
||
120 | 'submission' => 'nullable|array', |
||
121 | 'is_active' => 'sometimes|boolean', |
||
122 | 'is_public' => 'sometimes|boolean', |
||
123 | ]; |
||
124 | |||
125 | /** |
||
126 | * Whether the model should throw a |
||
127 | * ValidationException if it fails validation. |
||
128 | * |
||
129 | * @var bool |
||
130 | */ |
||
131 | protected $throwValidationExceptions = true; |
||
132 | |||
133 | /** |
||
134 | * Create a new Eloquent model instance. |
||
135 | * |
||
136 | * @param array $attributes |
||
137 | */ |
||
138 | public function __construct(array $attributes = []) |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | protected static function boot() |
||
156 | |||
157 | /** |
||
158 | * Get the options for generating the slug. |
||
159 | * |
||
160 | * @return \Spatie\Sluggable\SlugOptions |
||
161 | */ |
||
162 | public function getSlugOptions(): SlugOptions |
||
169 | |||
170 | /** |
||
171 | * The form may have many responses. |
||
172 | * |
||
173 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
174 | */ |
||
175 | public function responses(): HasMany |
||
179 | |||
180 | /** |
||
181 | * Get the owner model of the form. |
||
182 | * |
||
183 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
184 | */ |
||
185 | public function entity(): MorphTo |
||
189 | |||
190 | /** |
||
191 | * Activate the form. |
||
192 | * |
||
193 | * @return $this |
||
194 | */ |
||
195 | public function activate() |
||
201 | |||
202 | /** |
||
203 | * Deactivate the form. |
||
204 | * |
||
205 | * @return $this |
||
206 | */ |
||
207 | public function deactivate() |
||
213 | } |
||
214 |