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