use Illuminate\Database\Eloquent\Builder; // Define the macro function Builder::macro('active', function () { return $this->where('is_active', true); }); // Use the macro in your code $users = User::active()->get(); // This returns only the active users in the database
use Illuminate\Database\Eloquent\Builder; // Define the macro function Builder::macro('sort', function (string $column, string $direction = 'asc') { return $this->orderBy($column, $direction); }); // Use the macro in your code $users = User::sort('name', 'desc')->get(); // This sorts the results by the 'name' column in descending orderIt appears that this macro is part of the Illuminate\Database package library, which is included in the Laravel framework.