adrema/app/Form/Models/Form.php

71 lines
1.9 KiB
PHP
Raw Normal View History

2023-12-27 22:54:58 +01:00
<?php
namespace App\Form\Models;
use Cviebrock\EloquentSluggable\Sluggable;
2023-12-27 22:54:58 +01:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2024-01-29 22:07:33 +01:00
use Laravel\Scout\Searchable;
use Spatie\Image\Manipulations;
2024-01-12 23:29:18 +01:00
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
2024-01-12 23:29:18 +01:00
use Zoomyboy\MedialibraryHelper\DefersUploads;
2023-12-27 22:54:58 +01:00
2024-01-12 23:29:18 +01:00
class Form extends Model implements HasMedia
2023-12-27 22:54:58 +01:00
{
use HasFactory;
use Sluggable;
2024-01-12 23:29:18 +01:00
use InteractsWithMedia;
use DefersUploads;
2024-01-29 22:07:33 +01:00
use Searchable;
2023-12-27 22:54:58 +01:00
public $guarded = [];
public $casts = [
'config' => 'json',
2024-02-02 01:05:45 +01:00
'description' => 'json',
2023-12-27 22:54:58 +01:00
];
2023-12-31 21:46:52 +01:00
2024-01-14 13:51:48 +01:00
/**
* @return SluggableConfig
*/
public function sluggable(): array
{
return [
'slug' => ['source' => ['name']],
];
}
2024-01-12 23:29:18 +01:00
public function registerMediaCollections(): void
{
$this->addMediaCollection('headerImage')
->singleFile()
->maxWidth(fn () => 500)
->forceFileName(fn (Form $model, string $name) => $model->slug)
->registerMediaConversions(function (Media $media) {
$this->addMediaConversion('square')->fit(Manipulations::FIT_CROP, 400, 400);
});
2024-01-12 23:29:18 +01:00
}
2023-12-31 21:46:52 +01:00
/** @var array<int, string> */
public $dates = ['from', 'to', 'registration_from', 'registration_until'];
2024-01-29 22:07:33 +01:00
// --------------------------------- Searching ---------------------------------
// *****************************************************************************
/**
2024-01-29 22:07:33 +01:00
* Get the indexable data array for the model.
*
2024-01-29 22:07:33 +01:00
* @return array<string, mixed>
*/
2024-01-29 22:07:33 +01:00
public function toSearchableArray()
{
2024-01-29 22:07:33 +01:00
return [
'from' => $this->from->timestamp,
'to' => $this->to->timestamp,
'name' => $this->name,
];
}
2023-12-27 22:54:58 +01:00
}