Skip to content

Commit 08b3f51

Browse files
Merge pull request #2 from subhashladumor1/dev
docs .md file
2 parents 8844f27 + 7b2e9b4 commit 08b3f51

30 files changed

+973
-1964
lines changed

README.md

Lines changed: 76 additions & 476 deletions
Large diffs are not rendered by default.

composer.json

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
{
22
"name": "subhashladumor/laravel-helperbox",
3-
"description": "? Laravel HelperBox packs 600+ advanced helpers - SQL optimization, caching, APIs, AI tools, arrays, strings, Blade & model utilities. ?? Save time, boost performance & simplify coding for every project, from startups to enterprise.",
3+
"description": "Laravel HelperBox packs 600+ advanced helpers - SQL optimization, caching, APIs, AI tools, arrays, strings, Blade & model utilities. ?? Save time, boost performance & simplify coding for every project, from startups to enterprise.",
44
"type": "library",
55
"license": "MIT",
6-
"autoload": {
7-
"psr-4": {
8-
"Subhashladumor\\LaravelHelperbox\\": "src/"
9-
}
10-
},
6+
"version":"1.0.1",
7+
"keywords": [
8+
"laravel",
9+
"docker",
10+
"ci-cd",
11+
"github-actions",
12+
"devops",
13+
"deployment",
14+
"automation"
15+
],
1116
"authors": [
1217
{
1318
"name": "Subhash Ladumor"
1419
}
1520
],
16-
"minimum-stability": "stable",
1721
"require": {
1822
"php": "^8.0",
1923
"illuminate/support": "^9.0|^10.0|^11.0|^12.0",
@@ -32,5 +36,18 @@
3236
"Subhashladumor\\LaravelHelperbox\\HelperServiceProvider"
3337
]
3438
}
35-
}
39+
},
40+
"autoload": {
41+
"psr-4": {
42+
"Subhashladumor\\LaravelHelperbox\\": "src/"
43+
}
44+
},
45+
"scripts": {
46+
"test": "phpunit",
47+
"test-coverage": "phpunit --coverage-html coverage",
48+
"cs-check": "phpcs",
49+
"cs-fix": "phpcbf"
50+
},
51+
"minimum-stability": "stable",
52+
"prefer-stable": true
3653
}

docs/AdvancedAlgorithmHelpers.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
### AdvancedAlgorithmHelpers
2+
3+
Heaps, graphs, tries, segment trees, Fenwick trees, matrices, and more.
4+
5+
#### Function Index
6+
7+
- array_to_heap(array $array, bool $maxHeap = true): array
8+
- heap_extract_min(array &$heap)
9+
- heap_extract_max(array &$heap)
10+
- graph_shortest_path(array $graph, $start, $end): array|false
11+
- graph_has_cycle(array $graph, bool $directed = true): bool
12+
- graph_topological_sort(array $graph): array|false
13+
- union_find_create(int $n): array
14+
- union_find_union(array &$uf, int $a, int $b): void
15+
- union_find_find(array &$uf, int $x): int
16+
- trie_insert(array &$trie, string $word): void
17+
- trie_search(array $trie, string $word): bool
18+
- trie_prefix_search(array $trie, string $prefix): array
19+
- segment_tree_build(array $array): array
20+
- segment_tree_query(array $tree, int $l, int $r): int
21+
- segment_tree_update(array &$tree, int $index, int $value): void
22+
- fenwick_tree_build(array $array): array
23+
- fenwick_tree_sum(array $tree, int $index): int
24+
- fenwick_tree_update(array &$tree, int $index, int $delta): void
25+
- matrix_rotate_90(array $matrix): array
26+
- matrix_spiral_order(array $matrix): array
27+
28+
Internal helpers exposed in this file (for reference): `heapify`, `hasCycleDFS`, `collectWords`, `buildSegmentTree`, `querySegmentTree`, `updateSegmentTree`, `fenwickUpdate`.
29+
30+
#### Examples
31+
32+
```php
33+
$heap = array_to_heap([3,1,4,1,5], true);
34+
$min = heap_extract_min($heap);
35+
```
36+
37+

docs/AdvancedCacheHelpers.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### AdvancedCacheHelpers
2+
3+
Advanced caching patterns: stampede prevention, jittered TTLs, tagging, chunked payloads, compression, locks, rate limiting.
4+
5+
#### Function Index
6+
7+
- cache_with_jitter(string $key, int $baseTtl, int $jitterPercent = 10, callable $producer = null)
8+
- cache_versioned_key(string $baseKey, string|int $version): string
9+
- cache_remember_tagged(array|string $tags, string $key, int $ttl, callable $producer)
10+
- cache_invalidate_tags(array|string $tags): void
11+
- cache_chunked_set(string $keyPrefix, string $payload, int $chunkSize = 900000, int $ttl = 3600): int
12+
- cache_chunked_get(string $keyPrefix): ?string
13+
- cache_randomized_ttl(int $ttl, int $spread = 20): int
14+
- cache_precompute(string $key, int $ttl, callable $producer)
15+
- cache_invalidate_model(string $modelClass, string|int $id): void
16+
- cache_json_response(string $key, int $ttl, callable $producer): array
17+
- cache_lock_run(string $name, int $seconds, callable $callback)
18+
- rate_limit_check(string $key, int $maxAttempts, int $decaySeconds): bool
19+
- cache_diff_update(string $key, array $newData, int $ttl = 3600): array
20+
- cache_compress_set(string $key, mixed $value, int $ttl = 3600): void
21+
- cache_compress_get(string $key, mixed $default = null): mixed
22+
- cache_stampeded_guard(string $key, int $ttl, callable $producer)
23+
- cache_forget_by_prefix(string $prefix): int
24+
25+

docs/AdvancedDeveloperHelpers.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### AdvancedDeveloperHelpers
2+
3+
Developer productivity: timing, query tracing, SQL dump, deterministic seeding, and lightweight HTTP mocking.
4+
5+
#### Function Index
6+
7+
- dev_time_callable_ms(callable $fn, int $iterations = 1): array
8+
- dev_trace_queries(callable $fn): array
9+
- dev_sql_dump(string $table, array $where = []): string
10+
- dev_seed_random(int $seed): void
11+
- dev_http_mock(string $url, array $response, int $status = 200): callable
12+
13+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
### AdvancedLaravelDatabaseHelpers
2+
3+
High-level DB/Eloquent utilities: cloning, diffing, chunking, upserts, N+1 detection, backups, trends, ranking, and optimization.
4+
5+
#### Function Index
6+
7+
- model_clone($model, array $excludeAttributes = ['id','created_at','updated_at'])
8+
- model_diff($model1, $model2): array
9+
- model_to_tree($models, string $parentKey = 'parent_id', string $childrenKey = 'children'): array
10+
- db_safe_transaction(callable $callback, int $attempts = 1)
11+
- db_query_log(callable $callback): array
12+
- db_mass_insert(string $table, array $data, int $chunkSize = 1000): int
13+
- db_mass_upsert(string $table, array $data, array $uniqueKeys, int $chunkSize = 1000): int
14+
- db_stream_query($query, callable $callback, int $chunkSize = 1000): int
15+
- db_detect_n_plus_one($query, array $relations): array
16+
- db_auto_paginate($query, int $defaultPerPage = 15)
17+
- db_cache_results($query, string $cacheKey, int $ttl = 3600)
18+
- db_optimize_select_fields($query, array $fields)
19+
- db_merge_duplicates(string $table, array $criteria, callable $mergeCallback): int
20+
- db_detect_outliers(string $table, string $column, float $threshold = 2.0): array
21+
- db_mask_sensitive_data(array $data, array $sensitiveFields, string $mask = '*'): array
22+
- db_archive_old_rows(string $sourceTable, string $archiveTable, string $dateColumn, string $cutoffDate): int
23+
- db_auto_sharding(string $baseTable, string $shardKey, int $shardCount): array
24+
- db_get_trending_data(string $table, string $dateColumn, string $valueColumn, int $days = 30): array
25+
- db_rank_by_field($query, string $field, string $rankColumn = 'rank')
26+
- db_analyze_index_usage(string $table): array
27+
- db_optimize_table_structure(string $table): array
28+
- db_export_to_json(string $table, string $filePath, array $conditions = []): bool
29+
- db_import_from_json(string $table, string $filePath, bool $truncateFirst = false): int
30+
- db_create_backup(string $backupPath, array $tables = []): bool
31+
- db_restore_backup(string $backupPath): bool
32+
33+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
### AdvancedMathAlgorithmicHelpers
2+
3+
Number theory, linear algebra, FFT, optimization, combinatorics, geometry.
4+
5+
#### Function Index
6+
7+
- math_gcd_extended(int $a, int $b): array
8+
- math_is_prime_miller_rabin(int $n, int $k = 5): bool
9+
- math_generate_primes_sieve(int $n): array
10+
- math_factorial_bigint(int $n): string
11+
- math_modular_inverse(int $a, int $m): int|false
12+
- math_modular_pow(int $base, int $exp, int $mod): int
13+
- math_fibonacci_matrix(int $n): int
14+
- math_polynomial_evaluate(array $coeffs, float $x): float
15+
- math_interpolation_lagrange(array $points): array
16+
- math_determinant(array $matrix): float
17+
- math_matrix_inverse(array $matrix): array|false
18+
- math_matrix_multiply(array $a, array $b): array
19+
- math_convex_hull(array $points): array
20+
- math_fast_fourier_transform(array $real, array $imag): array
21+
- math_random_gaussian(float $mean = 0, float $stddev = 1): float
22+
- math_combinations(array $array, int $k): array
23+
- math_permutations(array $array): array
24+
- math_power_set(array $array): array
25+
- math_knapsack(array $weights, array $values, int $capacity): array
26+
- math_coin_change(array $coins, int $amount): int
27+
- math_simplex(array $objective, array $constraints, array $rhs): array|false
28+
29+
Helper functions: `math_polynomial_multiply`, `math_cross_product`, `fft_recursive`, `math_matrix_pow`.
30+
31+

docs/ApiHttpHelpers.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
### ApiHttpHelpers
2+
3+
Convenience wrappers around Laravel HTTP client and JSON API responses.
4+
5+
#### Function Index
6+
7+
- http_get_json(string $url, array $headers = []): array|false
8+
- http_post_json(string $url, array $data, array $headers = []): array|false
9+
- http_put_json(string $url, array $data, array $headers = []): array|false
10+
- http_delete_json(string $url, array $headers = []): array|false
11+
- http_status_message(int $code): string
12+
- http_is_success(int $code): bool
13+
- http_is_redirect(int $code): bool
14+
- http_is_error(int $code): bool
15+
- api_success(mixed $data = null, string $message = 'OK', int $code = 200)
16+
- api_error(string $message = 'Error', int $code = 400, mixed $errors = null)
17+
- api_validation_error(array $errors, string $message = 'Validation failed')
18+
- api_not_found(string $message = 'Not Found')
19+
- api_unauthorized(string $message = 'Unauthorized')
20+
- api_forbidden(string $message = 'Forbidden')
21+
- api_internal_error(string $message = 'Internal Server Error')
22+
- api_created(mixed $data = null, string $message = 'Created')
23+
- api_no_content()
24+
- api_paginate_response($data, int $page, int $perPage)
25+
- http_timeout(string $method, string $url, array $options = [], int $timeout = 30)
26+
- http_retry(string $method, string $url, array $options = [], int $retries = 3)
27+
- http_with_auth(string $method, string $url, string $token, array $options = [])
28+
- http_download(string $url, string $path): bool
29+
- http_upload(string $url, string $filePath, array $headers = []): array|false
30+
- http_validate_url(string $url): bool
31+
- http_get_domain(string $url): string|false
32+
- http_get_path(string $url): string|false
33+
- http_get_query(string $url): array
34+
- http_build_query_url(string $url, array $params): string
35+
- api_rate_limit_exceeded(string $message = 'Rate limit exceeded')
36+
- api_download_response(string $filePath, ?string $fileName = null)
37+
38+
#### Examples
39+
40+
```php
41+
$data = http_get_json('https://api.github.com');
42+
return api_success($data);
43+
```
44+
45+

docs/ArrayHelpers.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
### ArrayHelpers
2+
3+
Practical array utilities for flattening, grouping, plucking, keyed inserts, partitions, CSV conversion, padding, randomization, and more.
4+
5+
#### Function Index
6+
7+
- array_flatten_recursive(array $array, int $depth = 0): array
8+
- array_to_xml(array $array, string $rootElement = 'root', string $xmlVersion = '1.0', string $encoding = 'UTF-8'): string
9+
- array_shuffle_assoc(array $array): array
10+
- array_key_case(array $array, int $case = CASE_LOWER): array
11+
- array_group_by(array $array, callable|string $key): array
12+
- array_multi_search(array $array, mixed $search, bool $strict = false): array
13+
- array_pluck_recursive(array $array, string $key): array
14+
- array_random_key(array $array)
15+
- array_random_value(array $array)
16+
- array_insert_after(array $array, mixed $key, mixed $newKey, mixed $newValue): array
17+
- array_insert_before(array $array, mixed $key, mixed $newKey, mixed $newValue): array
18+
- array_first_key(array $array)
19+
- array_last_key(array $array)
20+
- array_first_value(array $array)
21+
- array_last_value(array $array)
22+
- array_partition(array $array, callable $callback): array
23+
- array_is_assoc(array $array): bool
24+
- array_is_list(array $array): bool
25+
- array_only_keys(array $array, array $keys): array
26+
- array_except_keys(array $array, array $keys): array
27+
- array_merge_recursive_distinct(array $array1, array $array2): array
28+
- array_diff_recursive(array $array1, array $array2): array
29+
- array_to_csv(array $array, string $delimiter = ',', string $enclosure = '"'): string
30+
- array_from_csv(string $csv, string $delimiter = ',', string $enclosure = '"'): array
31+
- array_split_chunks(array $array, int $size): array
32+
- array_pad_left(array $array, int $size, mixed $value = null): array
33+
- array_pad_right(array $array, int $size, mixed $value = null): array
34+
- array_to_collection(array $array): \Illuminate\Support\Collection
35+
- array_random_subset(array $array, int $count): array
36+
- array_to_object(array $array): object
37+
38+
#### Examples
39+
40+
```php
41+
$flat = array_flatten_recursive([[1, [2]], 3]); // [1,2,3]
42+
43+
$groups = array_group_by([
44+
['id' => 1, 'role' => 'admin'],
45+
['id' => 2, 'role' => 'user'],
46+
], 'role');
47+
// ['admin' => [...], 'user' => [...]]
48+
49+
$csv = array_to_csv([
50+
['id' => 1, 'name' => 'A'],
51+
['id' => 2, 'name' => 'B'],
52+
]);
53+
```
54+
55+

docs/BladeHelpers.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
### BladeHelpers
2+
3+
Blade-friendly conditionals, formatting helpers, directives support, and UI attributes.
4+
5+
#### Function Index
6+
7+
- blade_if_route(string|array $route): bool
8+
- blade_if_controller(string|array $controller): bool
9+
- blade_if_action(string|array $action): bool
10+
- blade_if_role(string|array $role): bool
11+
- blade_if_permission(string|array $permission): bool
12+
- blade_format_date(mixed $date, string $format = 'Y-m-d H:i:s'): string
13+
- blade_asset_version(string $file): string
14+
- blade_inline_svg(string $path, array $attributes = []): string
15+
- blade_component_exists(string $name): bool
16+
- blade_render_markdown(string $text): string
17+
- blade_loop_index(): int
18+
- blade_include_if_exists(string $view, array $data = []): string
19+
- blade_old_value(string $key, mixed $default = null)
20+
- blade_error_message(string $field): string
21+
- blade_has_error(string $field): bool
22+
- blade_csrf_token(): string
23+
- blade_method_field(string $method): string
24+
- blade_route_url(string $name, array $parameters = []): string
25+
- blade_active_class(string|array $route, string $class = 'active'): string
26+
- blade_checked(mixed $value, mixed $checked): string
27+
- blade_selected(mixed $value, mixed $selected): string
28+
- blade_disabled(bool $condition): string
29+
- blade_readonly(bool $condition): string
30+
- blade_required(bool $condition): string
31+
- blade_placeholder(string $field, string $default = ''): string
32+
- blade_help_text(string $field, string $default = ''): string
33+
34+
#### Examples
35+
36+
```blade
37+
<li class="{{ blade_active_class('dashboard') }}">...</li>
38+
@if(blade_if_role('admin')) ... @endif
39+
{!! blade_inline_svg('icons/logo.svg', ['class' => 'h-6']) !!}
40+
```
41+
42+

0 commit comments

Comments
 (0)