emi_sastra
asked on
Understanding Laravel Function
Hi All,
I have below code.
What is the purpose of unsetClauses ?
Thank you.
I have below code.
public function destroy(ManageUserRequest $request, User $user)
{
$this->userRepository->deleteById($user->id);
$user->email = $user->email . '_deleted';
// $user->deleted_at = now();
$user->save();
event(new UserDeleted($user));
return redirect()->route('admin.auth.user.deleted')->withFlashSuccess(__('alerts.backend.users.deleted'));
}
public function deleteById($id) : bool
{
$this->unsetClauses();
return $this->getById($id)->delete();
}
protected function unsetClauses()
{
$this->wheres = [];
$this->whereIns = [];
$this->scopes = [];
$this->take = null;
return $this;
}
What is the purpose of unsetClauses ?
Thank you.
The clauses are additional parts to a query, such as the WHERE statement etc. When you no longer need these additional parts, you can call unsetClasuses and it will remove them so that the next time you run a query, they won't be applied. All that code does is set the various properties of $this to an empty array.
ASKER
Hi Chris,
Should it be a mandatory, what if we omitted ?
Which query will be affected with/without the unsetClauses?
Thank you.
Should it be a mandatory, what if we omitted ?
Which query will be affected with/without the unsetClauses?
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Chris,
Great. I get it know.
Thank you.
Great. I get it know.
Thank you.