Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

Also is that even a good idea to be stringing along the relationships like I am from Listing <- Model <- Manufacturer?

As an experienced and efficient Laravel dev, would you be writing your model tests before even bothering with the seeders? I'm thinking that might help avoid this sort of obstacle/confusion... then again I know nothing I'm just getting my feet wet here, trying to make sense of it all. The seeders are simpler to me than testing since I haven't tried testing yet and thus it seems daunting still, so seeders I go coding.

Last updated 2 years ago.
0

See the reason I have their relationships that way is because I want Models to have to be unique but only paired with their Manufacturers. So even if two different manufacturers have say a model "3200", they'll have different IDs, and therefore if querying for that model you won't get that model from multiple manufacturers. Obviously. If you change a listing's model, the manufacturer will change accordingly. Duh. Pretty standard. Am I going about implementing it wrong though?

Last updated 2 years ago.
0

My creator migration:

<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateListingTables extends Migration { /** * Run the product tables' migrations. * * @return void */ public function up() { Schema::create('manufacturers', function(Blueprint $table) { $table->increments('id'); $table->string('name', 128)->unique; $table->timestamps(); }); Schema::create('models', function(Blueprint $table) { $table->increments('id'); $table->string('name', 128); $table->integer('manufacturer_id')->unsigned(); $table->foreign('manufacturer_id')->references('id')->on('manufacturers'); $table->timestamps(); }); Schema::create('listings', function(Blueprint $table) { $table->increments('id'); $table->string('name', 128); $table->integer('model_id')->unsigned(); $table->foreign('model_id')->references('id')->on('models'); $table->tinyInteger('length')->unsigned(); $table->enum('condition', array('New', 'Used')); $table->enum('layout', array('Owner', 'Charter')); $table->enum('hull_config', array('Monohull', 'Catamaran', 'Trimaran')); $table->timestamps(); //$table->index(array('model_id', 'condition')); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('listings'); Schema::drop('models'); Schema::drop('manufacturers'); } }
Last updated 2 years ago.
0

Adding protected $guarded = ['id']; to Listing model worked thanks to LordWaffle's advise but only for db:seed --class=ListingsTableSeeder. I still get the same error when I just run db:seed on the whole. Why will it work alone but not as the last in the sequence??

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

chimmel chimmel Joined 4 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.