Skip to content

Commit

Permalink
add system upload
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Nov 21, 2024
1 parent e3465b9 commit bfccfe1
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Http/Controllers/Api/V1/Admin/Catalog/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,18 @@ public function massUpdate(MassUpdateRequest $massUpdateRequest)
'message' => trans('Apis::app.admin.catalog.products.mass-operations.update-success'),
]);
}

/**
* Upload product images.
*
* @return \Illuminate\Http\Response
*/

public function upload(Request $request)
{
$this->upload($request->all(), 'images');

return response([], 201);

}
}
51 changes: 51 additions & 0 deletions src/Http/Controllers/Api/V1/Admin/System/TinyMCEController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace NexaMerchant\Apis\Http\Controllers\Api\V1\Admin\System;

use Illuminate\Support\Facades\Storage;

class TinyMCEController extends Controller
{
/**
* Storage folder path.
*
* @var string
*/
private $storagePath = 'tinymce';

/**
* Upload file from tinymce.
*
* @return void
*/
public function upload()
{
$media = $this->storeMedia();

if (! empty($media)) {
return response()->json([
'location' => $media['file_url']
]);
}

return response()->json([]);
}

/**
* Store media.
*
* @return array
*/
public function storeMedia()
{
if (! request()->hasFile('file')) {
return [];
}

return [
'file' => $path = request()->file('file')->store($this->storagePath),
'file_name' => request()->file('file')->getClientOriginalName(),
'file_url' => Storage::url($path),
];
}
}
5 changes: 5 additions & 0 deletions src/Routes/V1/Admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@
* Reporting routes.
*/
require 'reporting-routes.php';

/**
* System routes.
*/
require 'system-routes.php';
});
20 changes: 20 additions & 0 deletions src/Routes/V1/Admin/system-routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Illuminate\Support\Facades\Route;

use NexaMerchant\Apis\Http\Controllers\Api\V1\Admin\System\TinyMCEController;

/**
* System routes.
*/
Route::group([
'middleware' => ['auth:sanctum', 'sanctum.admin'],
'prefix' => 'system',
], function () {
/**
* TinyMCE routes.
*/
Route::controller(TinyMCEController::class)->prefix('tinymce')->group(function () {
Route::post('upload', 'upload');
});
});

0 comments on commit bfccfe1

Please sign in to comment.