Tables are
User Table:
id
name
email
etc.
Profile Table:
user_id
role
address
city
state
etc.
On tinker i did:
$user = App\User::with('profile')->find(3);
Output is:
App\User {#756
id: 3,
name: "Alejandra Kerluke Jr.",
email: "balistreri.laurel@example.com",
deleted_at: null,
created_at: "2016-06-23 05:12:03",
updated_at: "2016-06-29 11:05:45",
Profile: App\Profile {#768
user_id: 3,
role: "",
address: """
50111 Wendy Row Apt. 732
Kingburgh, OR 42164-7189
""",
city: "Manteland",
state: "Vermont",
country: "Belgium",
phone: "1-226-766-4182 x5574",
fax: "1-507-985-3523 x708",
zip: 48446,
status: 0,
deleted_at: null,
created_at: "2016-06-23 05:12:03",
updated_at: "2016-06-23 05:12:03",
},
}
Then i did:
>>> $user->name="YYYYYY"
>>> $user->email='abc@example.com'
>>> $user->profile->role = 'XXXXX'
>>> $user->push();
This throws the error:
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update `profiles` set `role` = inspector, `updated_at` = 2016-06-29 11:29:30 where `id` is null)'
I don't know what's wrong with this piece of code. I am new to Laravel and any kind of help will be appreciated.