sortBy(static fn ($item) => array_search($item->$key, $orderBy, true))->values(); }); Builder::macro('logSql', function (): Builder { /** @var Builder $this */ Log::info($this->toSql()); return $this; }); if (app()->runningUnitTests()) { UploadedFile::macro('fromFile', static function (string $path, ?string $name = null): UploadedFile { return UploadedFile::fake()->createWithContent($name ?? basename($path), File::get($path)); }); TestResponse::macro('log', function (string $file = 'test-response.json'): TestResponse { /** @var TestResponse $this */ File::put(storage_path('logs/' . $file), $this->getContent()); return $this; }); } } }