> For the complete documentation index, see [llms.txt](https://docs.enicebakerygh.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enicebakerygh.com/content-media-and-seo/media.md).

# Media Asset Management

This document details the media storage architecture, file upload security, digital asset library, and brand crest pipelines of Eniceberny Bakery and Culinary Hub.

***

## 1. Storage Architecture & Driver Abstraction

Eniceberny supports a dual-driver storage architecture configured via the `MEDIA_DISK` environment variable:

```mermaid
graph TD
    A[Staff File Upload /admin/media] --> B[Validation Gate: MIME & Max Size]
    B --> C{MEDIA_DISK Driver?}
    C -->|local / public| D[Local Filesystem storage/app/public/]
    C -->|s3| E[Cloudflare R2 / AWS S3 Bucket]
    D --> F[Public Symlink public/storage/]
    E --> G[Global CDN Edge Cache]
    F --> H[Browser Request via site_logo_url / asset]
    G --> H
```

### Storage Drivers Supported:

1. **Local Persistent Storage (`public`)**:
   * Files stored under `storage/app/public/`.
   * Exposed to the web via `php artisan storage:link` targeting `public/storage`.
2. **Cloud Object Storage (`s3` — Cloudflare R2 / AWS S3)**:
   * Zero-egress fee storage via Cloudflare R2.
   * S3-compatible endpoints configured with `AWS_ENDPOINT`, `AWS_BUCKET`, and `AWS_ACCESS_KEY_ID`.

***

## 2. Centralized Media Library (`/admin/media`)

The Media Library provides a centralized console for all images used across the catalog, marketing banners, and catering galleries:

### Key Media Attributes:

* **`title`**: Descriptive human-readable asset title.
* **`file_path`**: Relative path within the configured storage disk.
* **`disk`**: Driver used (`public` or `s3`).
* **`mime_type`**: Verified MIME type (e.g. `image/jpeg`, `image/png`, `image/webp`).
* **`file_size`**: Byte size of the asset.
* **`dimensions`**: Width and height in pixels (`1200x800`).
* **`folder`**: Logical organization (`branding`, `products`, `gallery`, `cms`).

***

## 3. Brand Identity & Logo Management Engine

The platform features a dedicated dynamic branding engine governed by `SettingController`:

### 3.1 Upload & Replacement Protocol (`POST /admin/settings/logo`)

* **MIME & Extension Security**: Strictly requires `image|mimes:jpeg,png,jpg,webp,svg|max:2048`.
* **Unique Name Generation**: Files are assigned a random cryptographic hash filename, preventing path traversal attacks and browser cache conflicts.
* **Target Folder**: `branding/` directory on the active storage disk.
* **Cache Invalidation**: Automatically clears the `all_site_settings` cache key so all storefront templates reflect the new logo instantly.

### 3.2 Global Helper Functions:

Developers and template designers interact with the logo via clean helper functions:

```php
// Returns the public web URL with fallback to default system asset
$logoUrl = site_logo_url();

// Returns absolute server path for embedding in DomPDF invoices
$logoPath = site_logo_path();

// Returns business title with fallback to "Eniceberny Bakery"
$siteName = site_name();
```

***

## 4. Deletion Guards & Asset Referential Integrity

To prevent broken images on live storefront pages:

* Before any media item can be deleted in `/admin/media`, the system checks whether it is currently bound as a primary image to any `Product`, `Category`, or `HomepageSection`.
* If active dependencies exist, the deletion is rejected with an explanatory message: *"Cannot delete this media asset because it is currently used by \[Product Name]"*.
* Destructive actions require explicit confirmation dialogues in the browser.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.enicebakerygh.com/content-media-and-seo/media.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
