Ok, I managed to get round this by using the findOrNew() function, assigning the values for employee_id and section_id on the new object created then calling save().
I think this is better practice as foreign keys shouldn't be mass assigned as far as I can make out. Visible, hidden, fillable, guarded with Foreign Keys
Might be of use to someone having a similar problem with create() or findOrCreate() in the future.
I have the same issue as you did, but when I use the findOrNew() function I don't get any kind of error, but it doesn't create a new record in the database.
I'm trying to update a profile of a user and if the profile isn't there create it.
$profile = Profile::findOrNew(['user_id' => $update->id], $cleanInput);
I get the following error with the above code
Column not found: 1054 Unknown column '[email protected]' in 'field list'
I have also tried firstOrNew with no luck.
$profile = Profile::firstOrNew(['user_id' => $update->id])->update(array_except($cleanInput, [
'email',
'alias',
'username',
'permissions',
'last_login',
'shooter_uuid',
'first_name',
'last_name',
'password',
'include',
]));
The above just returns the ID of the last profile
If I don't use array_except on the input data I get the following error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'field list'
How did you assign your variables and then save the data to the new record?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community