Laravel Clone or Reuse Query

Example of Laravel clone or reuse query.


// 1. query to get all users
$users = User::query();

// 2. filter by date
$users->whereDate('created_at', Carbon::today());

// 3. verified and not verified users
$verified_users = $users->clone()->where('verified', true)->get();
$not_verified_users = $users->clone()->where('verified', false)->get();

return $verified_users;


Wath on YouTube:

Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.