The error message "Argument #1 ($values) must be of type array, string given" suggests that the $request variable passed to the updateInterest method is not an array. To fix this, you can convert the $request object to an array using the toArray() method before passing it to the update() method. Here's the updated code:
public function updateInterest(Request $request)
{
$user_id = Auth::user()->id;
$interest = Interest::where('user_id', $user_id)->first();
if (!$interest) {
$interest = new Interest();
$interest->user_id = $user_id;
}
$interest->hobby = $request->input('hobby');
$interest->language_1 = $request->input('language_1');
$interest->language_2 = $request->input('language_2');
$interest->language_3 = $request->input('language_3');
$interest->language_4 = $request->input('language_4');
$interest->language_5 = $request->input('language_5');
$interest->marital_status = $request->input('marital_status');
$interest->children = $request->input('children') ? 1 : 0;
$interest->save();
}
In this updated code, we first check if an Interest record already exists for the current user. If it does, we update that record; otherwise, we create a new Interest record. We also use the input() method to retrieve the values from the $request object, and we convert the children value to a boolean using a ternary operator.