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

I have something similar to create a dynamic eloquent model. I'm assuming the Model you reference is extending Eloquent.

Try,

$temp_table_data = new TempTable();
$temp_table_data->setTable("selected_postcodes_{$timestamp_string}_{$userid}");
$data = $temp_table_data->payment()->get()->toArray();

I'm not sure why you made your own setTable name function, there is one in eloquent already.

Last updated 8 years ago.
0

Yeah it's still not working. Do my models look correct? Are you sure that Eloquent is meant to return multiple rows in this way and not just one row? (I know that might sound like a ridiculous question if it is).

0

I'm not sure how well it will work with a foreign key with spaces in it.

You might make sure the base table, without the payment relationship, is loading correctly.

$data = $temp_table_data->get()->toArray();

dd($data); // make sure there is data

Eloquent should return as many rows as there are in the db query.

One way to get the raw query is

$q = DB::getQueryLog();
dd($q);
0

You might make sure the base table, without the payment relationship, is loading correctly.

Just doing $data = $temp_table_data->get()->toArray(); does print out all the postcodes data from TempTable as hoped. So that's not the problem..

I'm not sure how well it will work with a foreign key with spaces in it.

Possibly... I took that space out in 'Vendor ZIP' temporarily just to see. It still doesn't work. I still see a [] in the browser. But the source code is a big line of CSS/Javascript - which I have never seen before. What is that all about?

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mikelovely mikelovely Joined 26 Mar 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.