laravel-gallery maintained by caasidev
Laravel Gallery
A plugin-like image gallery package for Laravel applications. Drop it into any Laravel project to get galleries and image uploads via a clean, modern API.
Features
- Gallery CRUD API endpoints
- Multiple image uploads per gallery
- Configurable storage disk and path
- Automatic file cleanup on deletion
- Database migrations and model factories
- Full Pest test suite targeting 100% coverage
- PHPStan level 7 and Laravel Pint enforcement
Requirements
- PHP ^8.3
- Laravel ^13.0
Installation
Install the package via Composer:
composer require caasidev/laravel-gallery
The service provider will be auto-discovered by Laravel.
Configuration
Publish the config file:
php artisan vendor:publish --tag=gallery-config
The default config is:
return [
'disk' => env('GALLERY_DISK', 'public'),
'path' => env('GALLERY_PATH', 'galleries'),
'middleware' => ['api', 'auth'],
];
The default disk is public, so make sure the storage link exists:
php artisan storage:link
The middleware value controls route-level protection. If your app is API-only (e.g. Sanctum), change it to ['api', 'auth:sanctum'] or any middleware your project uses:
'middleware' => ['api', 'auth:sanctum'],
Run the migrations:
php artisan migrate
Usage
API Endpoints
All gallery routes are authenticated and scoped to the current user. Galleries and images created through the API are owned by the authenticated user and hidden from other users.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/galleries |
List all galleries |
| POST | /api/v1/galleries |
Create a gallery |
| GET | /api/v1/galleries/{gallery} |
Show a gallery |
| PUT/PATCH | /api/v1/galleries/{gallery} |
Update a gallery |
| DELETE | /api/v1/galleries/{gallery} |
Delete a gallery |
| POST | /api/v1/galleries/{gallery}/images |
Upload images to a gallery |
| DELETE | /api/v1/galleries/{gallery}/images/{image} |
Delete a gallery image |
Creating a Gallery
curl -X POST http://your-app.test/api/v1/galleries \
-H "Accept: application/json" \
-F "name=Summer Photos" \
-F "description=A simple gallery" \
-F "image=@cover.jpg"
Uploading Images
curl -X POST http://your-app.test/api/v1/galleries/1/images \
-H "Accept: application/json" \
-F "images[]=@photo1.jpg" \
-F "images[]=@photo2.jpg"
Testing
composer test
With coverage (requires PCOV or Xdebug):
composer test:coverage
Or use Make:
make test-coverage
Static Analysis & Formatting
composer analyse # PHPStan
composer format # Laravel Pint
composer lint # Both
Or use Make:
make lint
Changelog
Please see CHANGELOG for more information.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see LICENSE for more information.