I want to use method destroy
to delete one or more users, so it suppose to recieve an array and then delete whatever values given:
public function destroy(Request $request)
{
// DB::table('users')->whereIn('id', $request->user)->delete();
dd(var_dump($request->user));
}
However, the method recieves it as string, which is the first id
passed, and does not recieve other values, how can i make it recieve the array as is ? thanks in advance
const deleteSelectedUsers = () => {
const ids = [];
selectedUsers.value.forEach((val) => {
ids.push(val.id);
});
router.delete(route("users.destroy", ids));
deleteUsers.value = false;
selectedUsers.value = null;
toast.add({
severity: "success",
summary: "Successful",
detail: "Users Deleted",
life: 3000,
});
};
2
Answers
Please check this answer if it helps you
and your controller function is this
In accordance with best practices, a typical Laravel Controller encompasses CRUD methods that handle individual model operations. However, if your requirements deviate from the standard CRUD operations, it is advisable to relocate the corresponding code to a new Controller tailored to your needs.
For instance, consider a
UserController
containing methods likeindex
,show
,edit
,update
, anddestroy
, each serving specific functionalities. However, if the task involves deleting multiple users, it might be more fitting to segregate this code into a distinct controller and organize it accordingly.My recommendation is to use an Invokable Controller, following these steps:
1. Create Route:
2. Develop the Invokable Controller:
3. Execute the API call using InertiaJs:
By employing this approach, your code adheres to best practices and maintains a cleaner, more modular structure, ensuring seamless management of user-related operations.