Answer the question
In order to leave comments, you need to log in
Correct table structure for subdomains?
Good evening. I'll go straight to the point.
There is a project that involves the creation of subdomains by users. Guests are registered as users, after which the user can create a 3rd level subdomain, http:// test .site.ru. Subdomains should be able to create categories and articles on that subdomain. How to properly design the structure of articles, categories, so that there is a link to a subdomain, that is, on the TEST subdomain ... only categories and articles belonging to this subdomain are shown. I threw in an approximate structure, but I can’t figure out where exactly to bind to a subdomain, either in categories, or in the articles themselves ... Tell me, how would it be more correct?
Category table
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->integer('parent_id')->unsigned()->nullable()->default(null);
$table->foreign('parent_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('set null');
$table->integer('sort')->default(0);
$table->string('name');
$table->string('slug')->unique();
$table->integer('visibility')->default(1);
/*$table->integer('domain_id');
$table->foreign('domain_id')->references('id')->on('domains')->onDelete('cascade');
$table->unsignedInteger('domain_id')->index('domains_category_id_index');*/
$table->string('type');
$table->string('meta_description');
$table->string('meta_keywords');
$table->timestamps();
});
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('category_id')->index('articles_category_id_index');
$table->unsignedInteger('user_id')->index('articles_user_id_index');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
$table->string('title');
$table->string('slug')->unique()->index('articles_slug_index');
$table->longText('content_source');
$table->longText('content_rendered');
$table->tinyInteger('visibility')->default(1);
$table->text('meta_description');
$table->text('meta_keywords');
$table->timestamp('published_at');
$table->timestamps();
});
Answer the question
In order to leave comments, you need to log in
When creating another subdomain by a user, add the subdomain to the Subdomains(id, name, user_id) table, and simply add a unique subdomain_id field to the Articles table, and then each article will be strictly linked to a specific subdomain.
Alternatively, you can leave out the subdomain_id field in the Articles table and determine whether the subdomain belongs to the user who added the article. Do this using the Subdomains table, which I wrote about above. But it's easier to immediately add the subdomain_id field
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question