Support the ongoing development of Laravel.io →
Eloquent Views Blade
Last updated 1 year ago.
0

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!

0

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();
		});
	}
Last updated 8 years ago.
0

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]);
0

Nice work! That would do it! Thanks for the update.

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

morphikon morphikon Joined 25 Jul 2015

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.