jeudi 21 mai 2020

Laravel Bulk Insert To Another Table From Selected Multiple Rows

I expected I can replicate multiple row from specific table to another table. But the problem, it cannot replicate password field data and spatie assignRole(). Whereas, all fields like email, name, username, etc are works properly.

public function approveMultiple(Request $request) {
        $get_ids = $request->ids;
        $ids = explode(',', $get_ids);

        $users = \App\Applicant::whereIn('id', $ids);
        $users->update(['status' => 'Approved']); 

        $find_selected = \App\Applicant::whereIn('id', $ids)->get();
        $find_selected->makeHidden(['status', 'id']);
        $find_selected->makeVisible(['password']);
        $new_users = $find_selected->toArray();
        $users = \App\User::insert($new_users);

        //problem still lays here
        //$users->assignRole('Applicant');
        //$users->save();

        return response()->json(['success' => "Selected User(s) successfully approved."]);
    }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3e91nXD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire