mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
add tags
This commit is contained in:
38
app/Console/Commands/Database/CreateTags.php
Normal file
38
app/Console/Commands/Database/CreateTags.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Database;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CreateTags extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'tags:create';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$tags = config('tags.tags');
|
||||
foreach ($tags as $tag) {
|
||||
$t = Tag::findOrCreate($tag['de'], 'search');
|
||||
$t->icon = $tag['icon'];
|
||||
$t->setTranslation('name', 'en', $tag['en']);
|
||||
$t->save();
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
25
app/Http/Livewire/Frontend/SearchByTag.php
Normal file
25
app/Http/Livewire/Frontend/SearchByTag.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Frontend;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Livewire\Component;
|
||||
|
||||
class SearchByTag extends Component
|
||||
{
|
||||
public string $country = 'de';
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.frontend.search-by-tag', [
|
||||
'tags' => Tag::query()
|
||||
->with([
|
||||
'courses.lecturer',
|
||||
])
|
||||
->withCount([
|
||||
'courses',
|
||||
])
|
||||
->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace App\Http\Livewire\Tables;
|
||||
|
||||
use App\Models\Course;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Rappasoft\LaravelLivewireTables\DataTableComponent;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Column;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter;
|
||||
|
||||
class CourseTable extends DataTableComponent
|
||||
{
|
||||
@@ -32,6 +34,23 @@ class CourseTable extends DataTableComponent
|
||||
->setPerPage(50);
|
||||
}
|
||||
|
||||
public function filters(): array
|
||||
{
|
||||
return [
|
||||
MultiSelectFilter::make('Tag')
|
||||
->options(
|
||||
Tag::query()
|
||||
->get()
|
||||
->mapWithKeys(fn($item, $key) => [$item->name => $item->name])
|
||||
->toArray()
|
||||
)
|
||||
->filter(function (Builder $builder, array $values) {
|
||||
ray($values);
|
||||
$builder->withAnyTags($values, 'search');
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
public function columns(): array
|
||||
{
|
||||
return [
|
||||
@@ -43,6 +62,10 @@ class CourseTable extends DataTableComponent
|
||||
->collapseOnMobile(),
|
||||
Column::make("Name", "name")
|
||||
->sortable(),
|
||||
Column::make("Tags")
|
||||
->label(
|
||||
fn($row, Column $column) => view('columns.courses.tags')->withRow($row)
|
||||
),
|
||||
Column::make("Termine")
|
||||
->label(
|
||||
fn($row, Column $column) => '<strong>'.$row->events_count.'</strong>'
|
||||
|
||||
@@ -8,11 +8,13 @@ use Spatie\Image\Manipulations;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use Spatie\Tags\HasTags;
|
||||
|
||||
class Course extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory;
|
||||
use InteractsWithMedia;
|
||||
use HasTags;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
|
||||
11
app/Models/Tag.php
Normal file
11
app/Models/Tag.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Tag extends \Spatie\Tags\Tag
|
||||
{
|
||||
public function courses()
|
||||
{
|
||||
return $this->morphedByMany(Course::class, 'taggable');
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Markdown;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
use Spatie\TagsField\Tags;
|
||||
use ZiffMedia\NovaSelectPlus\SelectPlus;
|
||||
|
||||
class Course extends Resource
|
||||
@@ -65,6 +66,8 @@ class Course extends Resource
|
||||
->conversionOnIndexView('thumb')
|
||||
->help('Lade hier Bilder hoch, um sie eventuell später in der Markdown Description einzufügen. Du musst vorher aber Speichern.'),
|
||||
|
||||
Tags::make('Tags')->type('search')->withLinkToTagResource(Tag::class),
|
||||
|
||||
Text::make('Name')
|
||||
->rules('required', 'string'),
|
||||
|
||||
|
||||
32
app/Nova/Tag.php
Normal file
32
app/Nova/Tag.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Nova;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
|
||||
class Tag extends Resource
|
||||
{
|
||||
public static $model = \App\Models\Tag::class;
|
||||
|
||||
public static $title = 'name';
|
||||
|
||||
public static $search = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function fields(Request $request)
|
||||
{
|
||||
return [
|
||||
Text::make('Name')->sortable(),
|
||||
|
||||
Text::make('Translation')->sortable(),
|
||||
|
||||
Select::make('Type')->options([
|
||||
'search' => 'search',
|
||||
]),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use App\Nova\Event;
|
||||
use App\Nova\Lecturer;
|
||||
use App\Nova\Participant;
|
||||
use App\Nova\Registration;
|
||||
use App\Nova\Tag;
|
||||
use App\Nova\Team;
|
||||
use App\Nova\User;
|
||||
use App\Nova\Venue;
|
||||
@@ -54,6 +55,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||
MenuItem::resource(Country::class),
|
||||
MenuItem::resource(Team::class),
|
||||
MenuItem::resource(User::class),
|
||||
MenuItem::resource(Tag::class),
|
||||
])
|
||||
->icon('key')
|
||||
->collapsable(),
|
||||
|
||||
Reference in New Issue
Block a user