Jamie Jamie - 5 months ago 80
PHP Question

Laravel sync not working with empty array

I've a method looks like this:

public function saveContacts(Request $request)
if($request->contacts) {
$contacts = collect($request->contacts)->pluck('id');

It's working but if
is an empty array it does not remove all records. What could be the case here?


You can do this:

if ($request->contacts) {
    $contacts = collect($request->contacts)->pluck('id')->toArray();
    if (empty($contacts)) {
    } else {