2023-12-27 22:54:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Models;
|
|
|
|
|
2024-01-12 22:52:42 +01:00
|
|
|
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;
|
2024-01-19 18:16:57 +01:00
|
|
|
use Spatie\Image\Manipulations;
|
2024-01-12 23:29:18 +01:00
|
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
|
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
2024-01-19 18:16:57 +01:00
|
|
|
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;
|
2024-01-12 22:52:42 +01:00
|
|
|
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
|
|
|
|
*/
|
2024-01-12 22:52:42 +01:00
|
|
|
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)
|
2024-01-19 18:16:57 +01:00
|
|
|
->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-12 22:52:42 +01:00
|
|
|
|
2024-01-29 22:07:33 +01:00
|
|
|
// --------------------------------- Searching ---------------------------------
|
|
|
|
// *****************************************************************************
|
|
|
|
|
2024-01-12 22:52:42 +01:00
|
|
|
/**
|
2024-01-29 22:07:33 +01:00
|
|
|
* Get the indexable data array for the model.
|
2024-01-12 22:52:42 +01:00
|
|
|
*
|
2024-01-29 22:07:33 +01:00
|
|
|
* @return array<string, mixed>
|
2024-01-12 22:52:42 +01:00
|
|
|
*/
|
2024-01-29 22:07:33 +01:00
|
|
|
public function toSearchableArray()
|
2024-01-12 22:52:42 +01:00
|
|
|
{
|
2024-01-29 22:07:33 +01:00
|
|
|
return [
|
|
|
|
'from' => $this->from->timestamp,
|
|
|
|
'to' => $this->to->timestamp,
|
|
|
|
'name' => $this->name,
|
|
|
|
];
|
2024-01-12 22:52:42 +01:00
|
|
|
}
|
2023-12-27 22:54:58 +01:00
|
|
|
}
|