Extend Laravel with macros:
Response Macro
Response::macro('success', function ($data = null) {
return Response::json([
'success' => true,
'data' => $data,
]);
});Collection Macro
Collection::macro('toUpper', function () {
return $this->map(fn($value) => strtoupper($value));
});Builder Macro
Builder::macro('whereLike', function ($column, $value) {
return $this->where($column, 'LIKE', "%{$value}%");
});Usage
return response()->success($data);
$items->toUpper();
User::whereLike('name', 'john')->get();