Help with shirt -> colors -> sizes laravel relationship

Posted 3 weeks ago by Gabotronix

Hi everybody, I'm trying to wrap my head about this relationship which I think is many-to-many, I have 3 models, a shirt model, a shirt color model and a shirtsize model. Now this is how I see things, I could say:

One shirt can be many colors and many sizes but you could also say a shirt will be ONE color and ONE size (a shirt can't be multiple colors/sizes at once...) , so this got me pretty confused. I got the feeling this has to be a many to many relationship between shirt, size and color but I'm not so sure how (and if I should) do this?

This are my migrations:

Schema::create('shirts', function (Blueprint $table) {
            $table->increments('id');
            $table->string('slug')->unique();
            $table->string('url')->unique();
            $table->string('title')->unique();
            $table->longText('body');
            $table->decimal('finalPrice', 5,2);
            $table->integer('totalCount');
            $table->string('image')->nullable();
            $table->boolean('isVisible')->default(false);
            $table->boolean('beenPublished')->default(false);
            $table->boolean('scheduleForMail')->default(false);
            $table->timestamps();
        });


Schema::create('shirtcolors', function (Blueprint $table) {
            $table->increments('id'); 
            $table->string('title');
            $table->string('hexColor');
            $table->timestamps();
        });



Schema::create('shirtsizes', function (Blueprint $table) {
            $table->increments('id'); 
            $table->string('title')->nullable();
            $table->timestamps();
        });

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

Reply to

Use Markdown with GitHub-flavored code blocks.