Skip to content

Commit 4251541

Browse files
authored
Merge pull request #23 from SproutPHP/dev_yanik
Updated docs
2 parents 17f7fce + 37ba006 commit 4251541

File tree

3 files changed

+76
-36
lines changed

3 files changed

+76
-36
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ Earlier releases (`v0.1.0-alpha.1` to `v0.1.7-alpha.1`) were experimental and do
77

88
---
99

10+
## [v0.1.7-alpha.3] - 2024-06-13
11+
12+
### Added
13+
- Storage root is now set to an absolute path by default for reliability (no .env needed)
14+
- Improved Storage helper documentation and usage
15+
- Enhanced symlink command for better cross-platform compatibility
16+
- Updated documentation for new storage system and best practices
17+
18+
### Fixed
19+
- Prevented duplicate/nested storage paths in uploads
20+
- General codebase and documentation improvements
21+
22+
---
23+
1024
## [v0.1.7-alpha.2] - 2025-07-15
1125

1226
### Added

DOCS.md

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@ This will run the production build process (minifies, strips dev code, precompil
504504
- The old `build` command is now replaced by `bloom` for clarity and branding.
505505
- Use this command before deploying your app to production.
506506

507-
## File Upload & Storage
507+
## File Upload & Storage (v0.1.7+)
508508

509-
SproutPHP now includes a Storage helper for easy file uploads and URL generation, saving files in `public/uploads` for web accessibility.
509+
SproutPHP now includes a robust Storage helper for file uploads and URL generation, saving files in `storage/app/public` for web accessibility via a symlink.
510510

511511
### Usage Example
512512

@@ -516,44 +516,71 @@ use Core\Support\Storage;
516516
// In your controller
517517
if ($request->hasFile('avatar')) {
518518
$path = Storage::put($request->file('avatar'), 'avatars');
519-
$url = Storage::url($path); // /uploads/avatars/filename.jpg
519+
$url = Storage::url($path); // /storage/avatars/filename.jpg
520520
}
521521
```
522522

523-
- Files are saved in `public/uploads/{subdir}`.
524-
- URLs are generated as `/uploads/{subdir}/{filename}`.
523+
- Files are saved in `storage/app/public/{subdir}`.
524+
- URLs are generated as `/storage/{subdir}/{filename}`.
525+
- The `public/storage` directory is a symlink (or junction on Windows) to `storage/app/public`.
525526

526-
---
527-
528-
## Modern Request File Access
527+
### Storage Configuration
529528

530-
You can now access uploaded files in controllers using:
529+
In `config/storage.php`:
531530

532531
```php
533-
$request->file('avatar'); // Returns the file array or null
534-
$request->hasFile('avatar'); // Returns true if a file was uploaded
532+
'public' => [
533+
'root' => env('STORAGE_PUBLIC_ROOT', 'storage/app/public'),
534+
'url' => env('STORAGE_PUBLIC_LINK', '/storage'),
535+
'visibility' => 'public',
536+
],
535537
```
536538

537-
Request data merges `$_GET`, `$_POST`, and JSON body for unified access.
539+
### Creating the Symlink
538540

539-
---
541+
To make uploaded files accessible via the web, create a symlink:
542+
543+
```bash
544+
php sprout symlink:create
545+
```
546+
- This links `public/storage` to `storage/app/public`.
547+
- On Windows, a directory junction is created for compatibility.
540548

541-
## File Validation: mimes & image
549+
### Folder Structure
542550

543-
You can validate file uploads with new rules:
551+
```
552+
project-root/
553+
├── public/
554+
│ ├── assets/
555+
│ ├── index.php
556+
│ └── storage/ # symlink → ../storage/app/public
557+
├── storage/
558+
│ └── app/
559+
│ └── public/
560+
│ └── avatars/
561+
│ └── uploadedfile.jpg
562+
```
544563

545-
- `mimes:jpg,png,gif` — File must have one of the allowed extensions
546-
- `image` — File must be a valid image (checked by MIME type)
564+
### Accessing Uploaded Files
547565

548-
**Example:**
566+
- After upload, files are accessible at `/storage/avatars/filename.jpg`.
567+
- The `Storage::url($path)` helper generates the correct public URL.
568+
569+
### Example Controller Snippet
549570

550571
```php
551-
$validator = new Validator($request->data, [
552-
'avatar' => 'required|image|mimes:jpg,jpeg,png,gif'
553-
]);
572+
if ($request->hasFile('avatar')) {
573+
$file = $request->file('avatar');
574+
$path = Storage::put($file, 'avatars');
575+
$avatarUrl = Storage::url($path); // Use in your views
576+
}
554577
```
555578

556-
---
579+
### Notes
580+
- Always use the `Storage` helper for uploads and URLs.
581+
- The storage root is now absolute for reliability.
582+
- No need to set or override the storage root in `.env` unless you have a custom setup.
583+
- The CLI symlink command ensures public access to uploaded files.
557584

558585
## HTMX File Upload with
559586

RELEASE_NOTES.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
# SproutPHP v0.1.7-alpha.2 Release Notes
1+
# SproutPHP v0.1.7-alpha.3 Release Notes
22

33
## 🎉 New Features & Improvements
44

5-
- **File Upload & Storage:** New Storage helper for easy file uploads and URL generation, saving files in `public/uploads`.
6-
- **Modern Request API:** Access uploaded files via `$request->file('avatar')` and `$request->hasFile('avatar')`.
7-
- **Unified Input:** Request data now merges `$_GET`, `$_POST`, and JSON body for easier access.
8-
- **Validation:** Added `mimes` and `image` rules for secure file validation.
9-
- **HTMX File Upload:** File upload with progress bar using only HTMX, no custom JS required.
10-
- **Error Handling:** Generic script to clear errors on focus for all fields.
11-
- **Docs:** Updated with new usage examples and best practices.
5+
- **Absolute Storage Path:** Storage root is now set to an absolute path by default for reliability; no need to set in .env for most use cases.
6+
- **Updated Storage Helper:** Improved documentation and usage for file uploads and URL generation.
7+
- **Symlink Command:** Enhanced for better cross-platform compatibility (Windows junctions, Linux/macOS symlinks).
8+
- **Documentation:** DOCS.md updated to reflect new storage system, usage, and best practices.
9+
- **Bugfix:** Prevented duplicate/nested storage paths in uploads.
10+
- **General Improvements:** Codebase and documentation refinements.
1211

1312
## 🛠️ Upgrade Guide
1413

15-
- Use the new Storage helper and request methods for file uploads.
16-
- Update your forms to use the new validation rules and error-clearing script.
14+
- Use the new absolute storage root (no .env override needed).
15+
- Run `php sprout symlink:create` to ensure correct symlink/junction for uploads.
1716
- See DOCS.md for updated usage and examples.
1817

1918
## 📅 Release Date
2019

21-
2025-07-15
20+
2024-06-13
2221

2322
## 📦 Framework Version
2423

25-
v0.1.7-alpha.2
24+
v0.1.7-alpha.3
2625

2726
---
2827

29-
**Release Date**: 2025-07-15
30-
**Framework Version**: v0.1.7-alpha.2
28+
**Release Date**: 2024-06-13
29+
**Framework Version**: v0.1.7-alpha.3
3130
**PHP Version**: 8.1+
3231
**Composer**: 2.0+

0 commit comments

Comments
 (0)