//User
$table->increments('id'); // -> integer('id')->unsigned();
so change this:
//Board
// $table->bigInteger('owner_id')->unsigned(); to:
$table->integer('owner_id')->unsigned();
Thanks. It's now integer
, but I'm still getting NULL
when I run var_dump(User::find(1)->boards);
. The SQL output hasn't changed, either.
run DB::getQueryLog(); after fetching what you wanted, this will return all the queries and we can examine what's not working then.
OK. I've got…
var_dump(User::find(1)->boards);
var_dump(DB::getQueryLog());
which outputs…
NULL
array(1) { [0]=> array(3) { ["query"]=> string(44) "select * from `users` where `id` = ? limit 1" ["bindings"]=> array(1) { [0]=> int(1) } ["time"]=> float(0.52) } }
The only thing I can think of is that you mistyped boards somewhere. There is no other way that Eloquent returns NULL from any relation. Check again User model and the relation definition.
It turns out I'd renamed the original User.php
to User_.php
, which was being loaded instead of my new User.php
file. Once I deleted the original and did dump-autoload
, it worked perfectly!
array(2) { [0]=> array(3) { ["query"]=> string(44) "select * from `users` where `id` = ? limit 1" ["bindings"]=> array(1) { [0]=> int(1) } ["time"]=> float(0.46) } [1]=> array(3) { ["query"]=> string(52) "select * from `boards` where `boards`.`owner_id` = ?" ["bindings"]=> array(1) { [0]=> int(1) } ["time"]=> float(0.31) } }
Thanks for your help!
For those that might come later, if you have camel case table names, laravel will convert it to snake case if you don't input the column name in the relationship declaration. Hope this can help someone!
Morialkar said:
For those that might come later, if you have camel case table names, laravel will convert it to snake case if you don't input the column name in the relationship declaration. Hope this can help someone!
THX!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community