I have a litte problem inputting data from client to server, where the value does not match and has an error. I want to add data using a pivot table with attach but the value I get does not match I tried several ways but failed. What I want after creating the document data then attach the user according to what has been inputted in the client.
The problem
Just want to take id from client for pivot maybe like that:
$document->sent_to()->attach($request->users);
here's the code I've made:
Server
try {
$document = Document::create([
'udin' => $request['udin'],
'slug' => $uuid,
'status' => self::$active,
]);
$document->sent_to()->attach($request['users']);
return ResponseFormatter::success(
DocumentResource::collection([$document])[0],
self::$saved
);
} catch (Exception $e) {
return ResponseFormatter::error([
'message' => self::$wrong,
'error' => $e->errors(),
], self::$failed, 500);
}
Client
