mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2026-01-31 11:13:18 +00:00
🚀 feat(news): add news management with upload functionality and category selection in the association module
This commit is contained in:
11
app/Enums/Icon.php
Normal file
11
app/Enums/Icon.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use ArchTech\Enums\Meta\MetaProperty;
|
||||
use Attribute;
|
||||
|
||||
#[Attribute]
|
||||
class Icon extends MetaProperty
|
||||
{
|
||||
}
|
||||
46
app/Enums/NewsCategory.php
Normal file
46
app/Enums/NewsCategory.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use ArchTech\Enums\From;
|
||||
use ArchTech\Enums\InvokableCases;
|
||||
use ArchTech\Enums\Meta\Meta;
|
||||
use ArchTech\Enums\Metadata;
|
||||
use ArchTech\Enums\Names;
|
||||
use ArchTech\Enums\Options;
|
||||
use ArchTech\Enums\Values;
|
||||
|
||||
#[Meta(Label::class, Color::class, Icon::class)]
|
||||
enum NewsCategory: int
|
||||
{
|
||||
use InvokableCases;
|
||||
use Names;
|
||||
use Values;
|
||||
use Options;
|
||||
use Metadata;
|
||||
use From;
|
||||
|
||||
#[Label('Organisation')] #[Color('cyan')] #[Icon('file-lines')]
|
||||
case ORGANISATION = 1;
|
||||
|
||||
public static function selectOptions()
|
||||
{
|
||||
return collect(self::options())
|
||||
->map(
|
||||
fn(
|
||||
$option,
|
||||
$name
|
||||
) => [
|
||||
'value' => $option,
|
||||
'label' => __(
|
||||
self::fromName($name)
|
||||
->label()
|
||||
),
|
||||
'icon' => self::fromName($name)
|
||||
->icon(),
|
||||
]
|
||||
)
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
18
app/Livewire/Forms/NotificationForm.php
Normal file
18
app/Livewire/Forms/NotificationForm.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Form;
|
||||
|
||||
class NotificationForm extends Form
|
||||
{
|
||||
#[Validate('required|string')]
|
||||
public $name = '';
|
||||
|
||||
#[Validate('required|numeric')]
|
||||
public $category = '';
|
||||
|
||||
#[Validate('nullable|string|min:5')]
|
||||
public $description = '';
|
||||
}
|
||||
36
app/Models/Notification.php
Normal file
36
app/Models/Notification.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\NewsCategory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
|
||||
class Notification extends Model implements HasMedia
|
||||
{
|
||||
use InteractsWithMedia;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'category' => NewsCategory::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function registerMediaCollections(): void
|
||||
{
|
||||
$this
|
||||
->addMediaCollection('pdf')
|
||||
->acceptsMimeTypes(['application/pdf'])
|
||||
->singleFile();
|
||||
}
|
||||
|
||||
public function einundzwanzigPleb(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EinundzwanzigPleb::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user