xtremer360
1 week ago

Blog Post and Project Sharing Attachments and Categories

Posted 1 week ago by xtremer360

I'm attempting to map out my personal blog site with the right migrations and models. I have posts that each have either one or multiple categories and attachments which can be an image or a video. I also have projects that can either have one or multiple categories as well and one or multiple attachments attached to the project.

My question is my description above with how a project and a blog post can both have multiple attachments and categories assigned to them the correct way to set up my migrations.

Schema::create('posts', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('title');
    ...
    $table->timestamps();
});

Schema::create('attachments', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->morphs('attachable');
    $table->string('path');
    $table->timestamps();
});

Schema::create('projects', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('name');
    $table->timestamps();
});

Schema::create('categories', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->morphs('categorable');
    $table->string('name');
    $table->timestamps();
});

Please sign in or create an account to participate in this conversation.