| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\MorphMany;
- use Illuminate\Database\Eloquent\Builder;
- class FormData extends Model
- {
- use HasFactory, SoftDeletes;
- protected $fillable = [
- 'uuid',
- 'name',
- 'email',
- 'phone',
- 'gender',
- 'message',
- 'submitted_at',
- 'category_id'
- ];
- protected $casts = [
- 'gender' => 'boolean',
- 'submitted_at' => 'datetime',
- 'is_banned' => 'boolean',
- ];
- protected static function booted()
- {
- static::creating(function ($model) {
- if (empty($model->uuid)) {
- $model->uuid = \Illuminate\Support\Str::uuid()->toString();
- }
- if (empty($model->submitted_at)) {
- $model->submitted_at = now();
- }
- });
- }
- public function comments(): MorphMany
- {
- return $this->morphMany(Comments::class, 'commentable');
- }
- public function category(): BelongsTo
- {
- return $this->belongsTo(Category::class);
- }
- public function scopeMale(Builder $query): Builder
- {
- return $query->where('gender', true);
- }
- public function scopeFemale(Builder $query)
- {
- return $query->where('gender', false);
- }
- public function scopeToday(Builder $query): Builder
- {
- return $query->whereDate('submitted_at', today());
- }
- }
|