mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
news module added
This commit is contained in:
38
app/Console/Commands/Database/MigrateLibraryItemSlugs.php
Normal file
38
app/Console/Commands/Database/MigrateLibraryItemSlugs.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Database;
|
||||
|
||||
use App\Models\LibraryItem;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class MigrateLibraryItemSlugs extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'library_items:slugs';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
foreach (LibraryItem::all() as $item) {
|
||||
$item->slug = str($item->name)->slug('-', 'de');
|
||||
$item->save();
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
32
app/Http/Livewire/News/ArticleOverview.php
Normal file
32
app/Http/Livewire/News/ArticleOverview.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\News;
|
||||
|
||||
use App\Models\LibraryItem;
|
||||
use Livewire\Component;
|
||||
use RalphJSmit\Laravel\SEO\Support\SEOData;
|
||||
|
||||
class ArticleOverview extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.news.article-overview', [
|
||||
'libraryItems' => LibraryItem::query()
|
||||
->with([
|
||||
'createdBy.roles',
|
||||
'lecturer',
|
||||
'tags',
|
||||
])
|
||||
->where('type', 'markdown_article')
|
||||
->whereHas('createdBy.roles',
|
||||
fn($query) => $query->where('roles.name', 'news-editor'))
|
||||
->get(),
|
||||
])->layout('layouts.app', [
|
||||
'SEOData' => new SEOData(
|
||||
title: __('News'),
|
||||
description: __('Here we post important news that is relevant for everyone.'),
|
||||
image: asset('img/einundzwanzig-wallpaper-benrath.png'),
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
27
app/Http/Livewire/News/InternArticleView.php
Normal file
27
app/Http/Livewire/News/InternArticleView.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\News;
|
||||
|
||||
use App\Models\LibraryItem;
|
||||
use Carbon\Carbon;
|
||||
use Livewire\Component;
|
||||
use RalphJSmit\Laravel\SEO\Support\SEOData;
|
||||
|
||||
class InternArticleView extends Component
|
||||
{
|
||||
public LibraryItem $libraryItem;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.news.intern-article-view')->layout('layouts.app', [
|
||||
'SEOData' => new SEOData(
|
||||
title: $this->libraryItem->name,
|
||||
description: $this->libraryItem->excerpt ?? __('Here we post important news that is relevant for everyone.'),
|
||||
author: $this->libraryItem->lecturer->name,
|
||||
image: asset('img/einundzwanzig-wallpaper-benrath.png'),
|
||||
published_time: Carbon::parse($this->libraryItem->created_at),
|
||||
type: 'article',
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
|
||||
@@ -48,7 +49,7 @@ class City extends Model
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom(['country.code', 'name'])
|
||||
->saveSlugsTo('slug')
|
||||
->usingLanguage('de');
|
||||
->usingLanguage(Cookie::get('lang', config('app.locale')));
|
||||
}
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Spatie\Image\Manipulations;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@@ -76,7 +77,7 @@ class Lecturer extends Model implements HasMedia
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom(['name'])
|
||||
->saveSlugsTo('slug')
|
||||
->usingLanguage('de');
|
||||
->usingLanguage(Cookie::get('lang', config('app.locale')));
|
||||
}
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Spatie\EloquentSortable\Sortable;
|
||||
use Spatie\EloquentSortable\SortableTrait;
|
||||
use Spatie\Image\Manipulations;
|
||||
@@ -12,6 +13,8 @@ use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use Spatie\ModelStatus\HasStatuses;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
use Spatie\Tags\HasTags;
|
||||
|
||||
class LibraryItem extends Model implements HasMedia, Sortable
|
||||
@@ -20,6 +23,7 @@ class LibraryItem extends Model implements HasMedia, Sortable
|
||||
use HasTags;
|
||||
use SortableTrait;
|
||||
use HasStatuses;
|
||||
use HasSlug;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -37,6 +41,14 @@ class LibraryItem extends Model implements HasMedia, Sortable
|
||||
'library_id' => 'integer',
|
||||
];
|
||||
|
||||
public function getSlugOptions(): SlugOptions
|
||||
{
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom(['name'])
|
||||
->saveSlugsTo('slug')
|
||||
->usingLanguage(Cookie::get('lang', config('app.locale')));
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Spatie\Image\Manipulations;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@@ -48,7 +49,7 @@ class Meetup extends Model implements HasMedia
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom(['name'])
|
||||
->saveSlugsTo('slug')
|
||||
->usingLanguage('de');
|
||||
->usingLanguage(Cookie::get('lang', config('app.locale')));
|
||||
}
|
||||
|
||||
public function registerMediaConversions(Media $media = null): void
|
||||
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Spatie\Image\Manipulations;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@@ -71,7 +72,7 @@ class Venue extends Model implements HasMedia
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom(['city.slug', 'name',])
|
||||
->saveSlugsTo('slug')
|
||||
->usingLanguage('de');
|
||||
->usingLanguage(Cookie::get('lang', config('app.locale')));
|
||||
}
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
|
||||
@@ -13,6 +13,7 @@ use Laravel\Nova\Fields\BelongsTo;
|
||||
use Laravel\Nova\Fields\BelongsToMany;
|
||||
use Laravel\Nova\Fields\Code;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Number;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
@@ -112,7 +113,8 @@ class LibraryItem extends Resource
|
||||
->options(
|
||||
config('languages.languages')
|
||||
)
|
||||
->rules('required', 'string')->searchable(),
|
||||
->rules('required', 'string')
|
||||
->searchable(),
|
||||
|
||||
Tags::make('Tags')
|
||||
->type('library_item')
|
||||
@@ -121,6 +123,19 @@ class LibraryItem extends Resource
|
||||
Text::make('Name')
|
||||
->rules('required', 'string'),
|
||||
|
||||
Text::make(__('Subtitle'), 'subtitle')
|
||||
->rules('nullable', 'string'),
|
||||
|
||||
Text::make(__('Excerpt'), 'excerpt')
|
||||
->rules('nullable', 'string')->help(__('This is the excerpt that is shown in the overview.')),
|
||||
|
||||
Text::make(__('Main image caption'), 'main_image_caption')
|
||||
->rules('nullable', 'string'),
|
||||
|
||||
Number::make(__('Time to read'), 'read_time')
|
||||
->rules('nullable', 'numeric')
|
||||
->help(__('How many minutes to read?')),
|
||||
|
||||
Select::make(__('Type'), 'type')
|
||||
->options(
|
||||
Options::forEnum(LibraryItemType::class)
|
||||
@@ -132,7 +147,9 @@ class LibraryItem extends Resource
|
||||
->rules('nullable', 'string')
|
||||
->help('Please paste the URL to the video here, or the link to the blog article, or the link to the book, or the Markdown itself.'),
|
||||
|
||||
BelongsTo::make(__('Lecturer/Content Creator'), 'lecturer', Lecturer::class)->searchable()->withSubtitles(),
|
||||
BelongsTo::make(__('Lecturer/Content Creator'), 'lecturer', Lecturer::class)
|
||||
->searchable()
|
||||
->withSubtitles(),
|
||||
|
||||
BelongsTo::make(__('Episode'), 'episode', Episode::class)
|
||||
->nullable()
|
||||
@@ -145,7 +162,8 @@ class LibraryItem extends Resource
|
||||
return $request->user()
|
||||
->hasRole('super-admin');
|
||||
})
|
||||
->searchable()->withSubtitles(),
|
||||
->searchable()
|
||||
->withSubtitles(),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user