Skip to content

Commit

Permalink
when product save and need delete the all images for it
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Mar 6, 2025
1 parent 74cfe2f commit 4f9a289
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ public function quickCreate(Request $request){

$images = $request->input('images');

// delete the product images
$product->images()->delete();

// add images to the product
$productImages = [];
foreach($images as $key=>$image) {
Expand Down
44 changes: 44 additions & 0 deletions src/Http/Middleware/AdminCacheResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace NexaMerchant\Apis\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;

class AdminCacheResponse
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// url the url path and query string as cache key, need sort query string
// when query string include clean-cache, and it's value is true, then clean cache

$cacheKey = $this->makePageCacheKey($request->fullUrl());

$cacheKey = 'api_cache_' . $cacheKey;

if (Cache::has($cacheKey)) {
$cacheData = Cache::get($cacheKey);
$cacheData = json_decode($cacheData, true);
return response()->json($cacheData);
}

$response = $next($request);

Cache::put($cacheKey, $response->getContent(), 3600); // Cache for

return $response;
}

private function makePageCacheKey($url){
return 'api_cache_' . Str::slug($url);
}
}

0 comments on commit 4f9a289

Please sign in to comment.