Download the PHP package nurbekjummayev/laravel-media-api without Composer

On this page you can find all versions of the php package nurbekjummayev/laravel-media-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-media-api

nurbekjummayev/laravel-media-api

Tests

Standalone media/file upload API for Laravel. Upload once, get an id, then each model links it from its own table. Private storage with temporary signed-URL access and automatic orphan cleanup. Built with spatie/laravel-package-tools.

Requirements

Install

Installing as a local path package If you keep the package in your app's `packages/` directory, add it to the root `composer.json`:

Files are stored under media/private and media/public (project root). Publish config if needed:

API

Method URI Auth
POST /api/v1/media auth:api + can:media.upload
GET /api/v1/media/{uuid}/view temporary signed URL
GET /api/v1/media/{uuid}/download temporary signed URL
DELETE /api/v1/media/{id} auth:api + can:media.delete

Upload accepts files[] (+ optional type=public|private) and returns Media[] with id, uuid, and a temporary signed url. Newly uploaded media are attached=false.

Uploads are atomic — the whole request runs in a DB transaction. If any file fails to write to disk or its Media record can't be saved, the transaction rolls back and every file already written for that request is removed, so no orphan files are left behind.

view/download are protected by Laravel temporary signed URLs (validated against APP_KEY, expire after config('media.url_ttl')). Read the signed view URL from $media->url and the download URL from $media->downloadUrl() — never hand-build these URLs. Inline view responses also send X-Content-Type-Options: nosniff and a sandbox CSP so SVG/HTML files can't execute scripts.

Linking media — each model owns its link

There is no shared polymorphic pivot. A model that needs media defines its own table/column.

Many files — a dedicated per-model table (e.g. product_photos):

Single file — an FK column on the model:

Auto-marking attached (recommended)

Use the InteractsWithMedia trait so linking flips attached=true automatically:

Without the trait, call app(MediaService::class)->markAttached($ids) yourself after linking.

Cascading delete

When a model using the trait is deleted, its media is cleaned up automatically: FK-column media (mediaColumns()) and pivot media (mediaRelations()) are deleted and the pivot links detached.

The physical file is only removed after the surrounding DB transaction commits (DB::afterCommit) — so if the delete is wrapped in a transaction that rolls back, the model, the media row, and the file all survive. The same guarantee applies to MediaService::delete() and the DELETE endpoint. With no active transaction the file is removed immediately.

For soft-deletable parents the deleting event also fires on soft delete, so media is removed then too. Override mediaColumns()/mediaRelations() (or hook forceDeleted yourself) if you need to keep media until a hard delete.

Orphan cleanup

Newly uploaded media are attached=false. Linking flips them to attached=true (via the trait above or MediaService::markAttached($ids)). The scheduled media:purge command (daily) deletes unattached media older than config('media.purge_after_hours') (24h) from disk + DB:

Always call markAttached after linking, otherwise the file is purged.

Owner

Each Media row stores an owner_id (set to the authenticated user on upload). The owner relation resolves to config('media.owner_model') — set it to User::class or any other model; null falls back to config('auth.providers.users.model').

Each upload also records the request ip and user_agent.

Security

Upload handling is hardened against the usual file-upload attacks:

Deployment note: as defence-in-depth, configure your web server to not execute scripts (PHP, CGI) under the media/ directories. The package never stores executable extensions, but disabling execution there removes the risk entirely even under misconfiguration.

Config

See config/media.php: owner_model, disks, allowed/blocked extensions, public_blocked_extensions, max size, signed-URL TTL (url_ttl), purge window, route prefix/middleware, and per-action upload_middleware/delete_middleware (the can:* permission checks are pulled from here, so you can rename permissions or add throttling without touching the package).

Testing

The package is tested with Pest on top of orchestra/testbench (no full Laravel app needed). CI runs the suite on PHP 8.3/8.4 against Laravel 12.


All versions of laravel-media-api with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
nurbekjummayev/laravel-api-response-helpers Version ^1.2
spatie/laravel-package-tools Version ^1.16
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nurbekjummayev/laravel-media-api contains the following files

Loading the files please wait ...