admin管理员组

文章数量:1122846

I'm currently working on a project using Laravel where I need to handle statuses across multiple types of entities (e.g., posts, comments, etc.). I've set up a polymorphic relationship to link statuses to different entities. Here's a brief overview of my setup:

Statuses Table:

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

Entity Statuses Table (Polymorphic Relationship):

  Schema::create('entity_statuses', function (Blueprint $table) {
    $table->id();
    $table->foreignId('status_id')->constrained('statuses');
    $table->morphs('entity');
    $table->timestamps();
});
$table->index(['entity_type', 'entity_id']);

My goal is to store all statuses of the models in a single table that relates them to the corresponding records, using only one table to keep the database size manageable, while also optimizing it as much as possible.

Question: How can I optimize this setup to handle large volumes of data efficiently? Are there best practices or alternative approaches for managing polymorphic relationships and statuses in a relational database? Any advice on improving indexing, caching strategies, or other optimization techniques would be greatly appreciated.

Additionally, I would like recommendations on the best database to use for this setup.

Thank you in advance!

本文标签: