Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent

i am using laravel 5.0 develop version

class User extends Model implements UserContract, RemindableContract {
    public function info()
    {
        return $this->hasOne('App\Info');
    }
}

and

php artisan tinker
(new App\User)->fill(['id'=>2,'email'=>'xxxx@gmail.com'])->info()->get();
DB::getQueryLog();

result is

'select * from `infos` where `infos`.`user_id` is null'

but i expected

'select * from 'infos' where 'infos'.`user_id` = 2

what is solution?? my expection is fault ?? help me!


============================== i solved this problem.. guarded property cause this problem

guarded = ['id'];

when

guarded = [];
fillable = ['id'];

result is

'select * from 'infos' where 'infos'.`user_id` = 2
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

dbwhddn10 dbwhddn10 Joined 25 Aug 2014

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.

© 2025 Laravel.io - All rights reserved.