corcel / corcel

Use WordPress backend with Laravel or any PHP application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

As A developer I want Documentation on how to upload, create, save and update Media to The Media Library So it's done it as intended

chrillep opened this issue · comments

First of thanks for a great package! ❤️

  • Corcel Version: 7.0.0
  • Framework Name & Version:
  • PHP Version: 8.3
  • Database Driver & Version:

Description:

There should be documentation on how to

  • upload
  • create
  • save
  • update
    Media to The Media Library

Steps To Reproduce:

Probably isn't documented because it's outside of the scope of what Corcel does currently, which is read and write to Wordpress Databases using Eloquent.

Attachments are just posts with Post Type = "Attachment", as well as a mime type. The file path is attached via post_meta.

Usually Wordpress does your file upload through normal PHP file upload actions, does some resizing if it's possible then puts it in wp-content/uploads/YYYY/MM/filename.extension

Corcel can only write to the database given it's current configuration. In order to upload media, you'd either need to have the wordpress theme directory as a storage disk in Laravel, or to use the Wordpress API.

I would personally go the API route as there are

  1. already api endpoints for creating media: (https://developer.wordpress.org/rest-api/reference/media/#definition-2)
  2. Already several PHP libraries that consume this API (eg https://github.com/rickwest/laravel-wordpress-api)
  3. Having storage connected to the wp-content folder doesn't "feel" right to me

TLDR

  1. Corcel can't without disk access somehow
  2. Use the API rather than Storage:: facade
  3. Submit a Pull request that creates a new file called Attachment.php in corcel/src/Model/ that extends Post that overrides the create method on Attachcments and does it via the API
    4)???
  4. Profit!

Everything you wrote is correct 😀🙌.

Thanks for talong the time to write ❤️.

It should be well documented 😉.

The is a an attachment Class already.
That's why I wanted this in the first place.

https://github.com/corcel/corcel/blob/8.0/src/Model/Attachment.php

I'll have a 👀 at the referenced package.