| 1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- namespace App\Models;
- /*
- * WebForm — модель веб-формы из конструктора форм.
- * Таблица: web_forms
- * Поле fields хранит JSON-массив объектов: [{label, name, type, width, required, options[]}, ...]
- * Связи: hasMany Lead
- */
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- class WebForm extends Model
- {
- protected $fillable = ['title', 'slug', 'notify_email', 'fields', 'is_active'];
- protected $casts = [
- 'fields' => 'array',
- 'is_active' => 'boolean',
- ];
- // Заявки, поступившие через эту форму
- public function leads(): HasMany
- {
- return $this->hasMany(Lead::class, 'form_id');
- }
- // Количество непросмотренных заявок
- public function unreadLeadsCount(): int
- {
- return $this->leads()->whereNull('read_at')->count();
- }
- }
|