<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('kennis_artikelen', function (Blueprint $table) {
            $table->id();
            $table->string('titel');
            $table->text('inhoud');
            $table->foreignId('auteur_id')->constrained('users')->restrictOnDelete();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('kennis_artikel_tag', function (Blueprint $table) {
            $table->foreignId('kennis_artikel_id')->constrained('kennis_artikelen')->cascadeOnDelete();
            $table->foreignId('tag_id')->constrained()->cascadeOnDelete();
            $table->primary(['kennis_artikel_id', 'tag_id']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('kennis_artikel_tag');
        Schema::dropIfExists('kennis_artikelen');
    }
};
