I would do a dump of the queries from the DB facade, using DB::getQueryLog() and check the queries being ran. To me it sounds like some bad relations in the database itself, the code looks looks good as far as I can see.
Good luck!
Results from querylog:
array:2 [▼
0 => array:3 [▼
"query" => "select * from `members`"
"bindings" => []
"time" => 0.36
]
1 => array:3 [▼
"query" => "select * from `titles` where `titles`.`id` in (?)"
"bindings" => array:1 [▼
0 => 1
]
"time" => 0.32
]
]
The migrations:
public function up()
{
Schema::create('titles', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
});
}
public function up()
{
Schema::create('members', function(Blueprint $table)
{
$table->increments('id');
$table->integer('roll_no');
$table->integer('title_id')->unsigned();
$table->foreign('title_id')->references('id')->on('titles');
$table->string('first_names');
$table->string('last_name');
$table->date('dob');
$table->string('address1');
$table->string('address2')->nullable();
$table->string('suburb');
$table->string('postcode');
$table->string('phone_home')->nullable();
$table->string('phone_work')->nullable();
$table->string('phone_fax')->nullable();
$table->string('phone_mobile')->nullable();
$table->string('email')->nullable();
$table->timestamps();
});
}
Found the issue.
I was using toArray() in the contorller:
$members = Member::with('title')->get()->toArray();
return view('members.list', ['members' => $members]);
When it should have been:
$members = Member::with('title')->get();
return view('members.list', ['members' => $members]);
Nice work! That would do it! Thanks for the update.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community