Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

behnampmdg3's avatar

A database design question. Is this the best approach?

Currently I got these 3:

CREATE TABLE `courses` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `active` int(11) NOT NULL DEFAULT '1',
  `description` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Users (authors)

CREATE TABLE `users` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email_verified_at` timestamp NULL DEFAULT NULL,
  `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_email_unique` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Members (students)

CREATE TABLE `members` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email_verified_at` timestamp NULL DEFAULT NULL,
  `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `members_email_unique` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Wanna make sure the relationship is set properly before I start:

Since each member can be in different courses, I will create member_course table with 4 columns

Schema::create('member_course', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigIncrements('course_id');
            $table->bigIncrements('member_id');
            $table->timestamps();
        });

Is this the best approach?

0 likes
3 replies
amitkadam's avatar

What if your users want to join a course?

Better way, I have used is instead of members table, save members data in users table and add new column = role

role=1 for users and role=2 for other users, or members

any one can login with Laravel's default login system and letter you can decide, who is log in user and where should redirect to him... on user dashboard or on courses dashboard!

Best of luck!

shedcollective's avatar

@mulugu he is ALREADY creating a pivot table.

i agree with @amitkadam no need for duplication.. but i dont see why you need member anyway.. a user will want to join a course right? you have pivot there so you can see who has joined a course and who hasnt

Please or to participate in this conversation.