- harlekoySun Oct 25 2026 00:09:39 GMT+0000 (Coordinated Universal Time)
Also this @glennmichael123
return (new Folder($this->client))->setMedia($this->id);
also looking at this
Media model
#6
7 files
+1700
-76
| @@ -0,0 +1,227 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | namespace Meema\MeemaApi\Models; | |
| 4 | ||
| 5 | use Meema\MeemaApi\Client; | |
| 6 | use Meema\MeemaApi\Response\Response; | |
| 7 | ||
| 8 | class Media | |
| 9 | { | |
| 10 | /** | |
| 11 | * @var \Meema\MeemaApi\Client | |
| 12 | */ | |
| 13 | protected $client; | |
| 14 | ||
| 15 | /** | |
| 16 | * @var int | |
| 17 | */ | |
| 18 | protected $id; | |
| 19 | ||
| 20 | /** | |
| 21 | * @var object | |
| 22 | */ | |
| 23 | protected $model; | |
| 24 | ||
| 25 | /** | |
| 26 | * Construct media model. | |
| 27 | * | |
| 28 | * @param Meema\MeemaApi\Client $client | |
| 29 | */ | |
| 30 | public function __construct(Client $client) | |
| 31 | { | |
| 32 | $this->client = $client; | |
| 33 | } | |
| 34 | ||
| 35 | /** | |
| 36 | * List all media. | |
| 37 | * | |
| 38 | * @return array | |
| 39 | */ | |
| 40 | public function all(): array | |
| 41 | { | |
| 42 | return $this->client->request('GET', 'media'); | |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * Get specific media. | |
| 47 | * | |
| 48 | * @return array | |
| 49 | */ | |
| 50 | public function get($id = null) | |
| 51 | { | |
| 52 | if ($this->model) { | |
| 53 | return $this->fetchMediaForFolder($this->model->getId()); | |
| 54 | } | |
| 55 | ||
| 56 | if (! $id) { | |
| 57 | return $this->all(); | |
| 58 | } | |
| 59 | ||
| 60 | $ids = is_array($id) ? $id : func_get_args(); | |
| 61 | ||
| 62 | return $this->client->request('GET', 'media/show', ['media_ids' => $ids]); | |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Get specific folders. | |
| 67 | * | |
| 68 | * @param int $id | |
| 69 | * | |
| 70 | * @return array | |
| 71 | */ | |
| 72 | public function find($id) | |
| 73 | { | |
| 74 | $response = $this->client->request('GET', "folders/${id}"); | |
| 75 | ||
| 76 | return new Response($this, $response); | |
| 77 | } | |
| 78 | ||
| 79 | /** | |
| 80 | * Create media. | |
| 81 | * | |
| 82 | * @param string $name | |
| 83 | * | |
| 84 | * @return array | |
| 85 | */ | |
| 86 | public function create($name): array | |
| 87 | { | |
| 88 | $name = is_array($name) ? $name : compact('name'); | |
| 89 | ||
| 90 | return $this->client->request('POST', "media/{$this->client->getAccessKey()}", $name); | |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * Update media. | |
| 95 | * | |
| 96 | * @param int $id | |
| 97 | * @param string $name | |
| 98 | * | |
| 99 | * @return array | |
| 100 | */ | |
| 101 | public function update($id, $name): array | |
| 102 | { | |
| 103 | $name = is_array($name) ? $name : compact('name'); | |
| 104 | ||
| 105 | return $this->client->request('PATCH', "media/{$id}/file-name", $name); | |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * Delete a media. | |
| 110 | * | |
| 111 | * @param int $id | |
| 112 | * | |
| 113 | * @return null | |
| 114 | */ | |
| 115 | public function delete($id = null) | |
| 116 | { | |
| 117 | return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]); | |
| 118 | } | |
| 119 | ||
| 120 | /** | |
| 121 | * Archive a media. | |
| 122 | * | |
| 123 | * @param int $id | |
| 124 | * | |
| 125 | * @return array | |
| 126 | */ | |
| 127 | public function archive($id = null): array | |
| 128 | { | |
| 129 | return $this->client->request('POST', "media/{$id}/archive"); | |
| 130 | } | |
| 131 | ||
| 132 | /** | |
| 133 | * Unarchive a media. | |
| 134 | * | |
| 135 | * @param int $id | |
| 136 | * | |
| 137 | * @return array | |
| 138 | */ | |
| 139 | public function unarchive($id): array | |
| 140 | { | |
| 141 | return $this->client->request('POST', "media/{$id}/unarchive"); | |
| 142 | } | |
| 143 | ||
| 144 | /** | |
| 145 | * Make a media private. | |
| 146 | * | |
| 147 | * @param int $id | |
| 148 | * | |
| 149 | * @return array | |
| 150 | */ | |
| 151 | public function makePrivate($id): array | |
| 152 | { | |
| 153 | return $this->client->request('PATCH', "media/{$id}/make-private"); | |
| 154 | } | |
| 155 | ||
| 156 | /** | |
| 157 | * Make a media public. | |
| 158 | * | |
| 159 | * @param int $id | |
| 160 | * | |
| 161 | * @return array | |
| 162 | */ | |
| 163 | public function makePublic($id): array | |
| 164 | { | |
| 165 | return $this->client->request('PATCH', "media/{$id}/make-public"); | |
| 166 | } | |
| 167 | ||
| 168 | /** | |
| 169 | * Duplicate a media. | |
| 170 | * | |
| 171 | * @param int $id | |
| 172 | * | |
| 173 | * @return array | |
| 174 | */ | |
| 175 | public function duplicate($id): array | |
| 176 | { | |
| 177 | return $this->client->request('POST', "media/{$id}/duplicate"); | |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * Initialize the folder model. | |
| 182 | * | |
| 183 | * @return Meema\MeemaApi\Models\Folder | |
| 184 | */ | |
| 185 | public function folders($id = null) | |
| 186 | { | |
| 187 | $this->id = $id; | |
| 188 | ||
| 189 | return (new Folder($this->client))->setMedia($this); | |
| 190 | } | |
| 191 | ||
| 192 | /** | |
| 193 | * Fetch the media for the folder. | |
| 194 | * | |
| 195 | * @param int $id | |
| 196 | * | |
| 197 | * @return array | |
| 198 | */ | |
| 199 | public function fetchMediaForFolder($id): array | |
| 200 | { | |
| 201 | return $this->client->request('GET', "folders/{$id}/media"); | |
| 202 | } | |
| 203 | ||
| 204 | /** | |
| 205 | * Initialize media model. | |
| 206 | * | |
| 207 | * @param Meema\MeemaApi\Models\Folder $folder | |
| 208 | * | |
| 209 | * @return self | |
| 210 | */ | |
| 211 | public function setFolder($folder): self | |
| 212 | { | |
| 213 | $this->model = $folder; | |
| 214 | ||
| 215 | return $this; | |
| 216 | } | |
| 217 | ||
| 218 | /** | |
| 219 | * Get the protected id. | |
| 220 | * | |
| 221 | * @return int | |
| 222 | */ | |
| 223 | public function getId() | |
| 224 | { | |
| 225 | return $this->id; | |
| 226 | } | |
| 227 | } | |