@@ -15,57 +15,72 @@ composer require codemonster-ru/support
1515
1616## 🧩 Provided Helpers
1717
18- | Function | Description |
19- | ---------------------- | --------------------------------------------- |
20- | ` config() ` | Get or set configuration values |
21- | ` env() ` | Read environment variables |
22- | ` view() ` / ` render() ` | Render or return a view instance |
23- | ` router() ` / ` route() ` | Access router instance |
24- | ` request() ` | Get the current HTTP request |
25- | ` response() ` | Create a new HTTP response |
26- | ` json() ` | Return a JSON response |
27- | ` abort() ` | Throw an HTTP-like exception with status code |
28- | ` session() ` | Read, write, or access session store |
29- | ` dump() ` / ` dd() ` | Debugging utilities (print and exit) |
18+ | Function | Description |
19+ | ---------------------- | -------------------------------------------- |
20+ | ` config() ` | Get or set configuration values |
21+ | ` env() ` | Read environment variables |
22+ | ` view() ` / ` render() ` | Render or return a view instance |
23+ | ` router() ` / ` route() ` | Access router instance |
24+ | ` request() ` | Get the current HTTP request |
25+ | ` response() ` | Create a new HTTP response |
26+ | ` json() ` | Return a JSON response |
27+ | ` abort() ` | Throw an HTTP-like exception |
28+ | ` session() ` | Read or write session data |
29+ | ` db() ` | Get a database connection (if installed) |
30+ | ` schema() ` | Schema builder (if database package present) |
31+ | ` transaction() ` | Run a DB transaction |
32+ | ` dump() ` / ` dd() ` | Debugging utilities |
33+
34+ > These helpers are framework‑agnostic and automatically enabled when installed.
3035
3136## 🚀 Usage
3237
33- All helpers are automatically registered via Composer’s autoloading.
34- You can call them from anywhere in your application.
35-
3638``` php
3739<?php
3840
3941require __DIR__ . '/vendor/autoload.php';
4042
41- // Environment variables
42- $value = env('APP_ENV', 'production');
43+ // ENV
44+ $env = env('APP_ENV', 'production');
4345
44- // Configuration
46+ // Config
4547config(['app.name' => 'Codemonster']);
48+ echo config('app.name');
4649
47- echo config('app.name'); // Codemonster
48-
49- // HTTP request and response
50+ // Requests & Responses
5051$request = request();
51- $response = response('Hello World', 200);
52- $response->send();
52+ return response('Hello World', 200);
5353
5454// Router
5555router()->get('/', fn() => response('Home'));
56- router()->post('/contact', fn() => response('Contact form submitted'));
5756
58- // View rendering
57+ // Views
5958echo render('emails.welcome', ['user' => 'Vasya']);
6059
61- // Debugging
60+ // Debug
6261dump($request);
63- dd('Goodbye ');
62+ dd('Bye! ');
6463```
6564
66- ## 🧪 Testing
65+ ## 🗄 Database Helpers (optional)
66+
67+ If ` codemonster-ru/database ` is installed:
68+
69+ ``` php
70+ $conn = db(); // default connection
71+ $conn = db('mysql'); // named connection
72+
73+ schema()->create('users', function ($table) {
74+ $table->id();
75+ $table->string('name');
76+ });
6777
68- You can run tests with the command:
78+ transaction(function ($db) {
79+ $db->table('logs')->insert(['msg' => 'ok']);
80+ });
81+ ```
82+
83+ ## 🧪 Testing
6984
7085``` bash
7186composer test
0 commit comments