Based on your last comment, I think you are expecting someone to write the code for you, right?
Here is how you write seeder: https://laravel.com/docs/9.x/seeding#using-model-factories
and the example has uses a factory with a relationship.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to use php tinker to post data into my db, but i am having issues because of the relationships involved.
public function up()
{
Schema::create('questions', function (Blueprint $table) {
$table->id();
$table->string('the_question');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
public function up()
{
Schema::create('options', function (Blueprint $table) {
$table->increments('id');
$table->string('the_option');
$table->unsignedBigInteger('question_id');
$table->foreign('question_id')->references('id')->on('questions');
$table->timestamps();
});
}
public function up()
{
Schema::create('answers', function (Blueprint $table) {
$table->increments('id');
$table->string('correct_answer');
$table->unsignedBigInteger('question_id');
$table->foreign('question_id')->references('id')->on('questions');
$table->timestamps();
});
}
or how can i use factory or seeder to go about it. One question with four options and the correct answer
Based on your last comment, I think you are expecting someone to write the code for you, right?
Here is how you write seeder: https://laravel.com/docs/9.x/seeding#using-model-factories
and the example has uses a factory with a relationship.
Please or to participate in this conversation.