|
@@ -12,7 +12,7 @@ use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Str;
|
|
|
use Packages\Product\Models\Attachment;
|
|
|
use Packages\Product\Models\Draft;
|
|
|
-use Packages\Product\Traits\Attachments;
|
|
|
+use Packages\Product\Traits\Uploads;
|
|
|
use Packages\Product\Http\Requests\ProductRequest;
|
|
|
use Packages\Product\Http\Requests\ProductRequestEdit;
|
|
|
use Packages\Product\Models\Product;
|
|
@@ -100,12 +100,12 @@ class ProductController extends Controller
|
|
|
// ->withErrors( ['error_message' => 'حتما باید یک فایل آپلود شود.'] )
|
|
|
// ->withInput( $request->all() );
|
|
|
// }
|
|
|
-// dd($draft->attachments);
|
|
|
+// dd($draft->attachments->count() == 0);
|
|
|
$product = Product::create($data);
|
|
|
$product->categories()->sync($request->categories);
|
|
|
|
|
|
- Attachment::where('parent_type', 'Packages\Product')->where('parent_id', $draft->id)
|
|
|
- ->update(['parent_type' => 'Packages\Product', 'parent_id' => $product->id]);
|
|
|
+ Upload::where('parent_type', 'Packages\Product')
|
|
|
+ ->update(['parent_type' => 'image\Product']);
|
|
|
$draft->delete();
|
|
|
|
|
|
if ($request->has('gallery_image')) {
|
|
@@ -151,8 +151,8 @@ class ProductController extends Controller
|
|
|
'discription' => $request->discription,
|
|
|
'creator_id' => auth()->user()->id,
|
|
|
];
|
|
|
- $product->update($data);
|
|
|
- $product->categories()->sync($request->categories);
|
|
|
+
|
|
|
+
|
|
|
if ($request->has('gallery_image')) {
|
|
|
$file = $request->only('gallery_image', 'captionGallery', 'descriptionGallery');
|
|
|
$type = 'gallery_image';
|
|
@@ -164,9 +164,10 @@ class ProductController extends Controller
|
|
|
$file = $request->file('featured_image');
|
|
|
$type = 'featured_image';
|
|
|
$diskName = 'product';
|
|
|
- $this->uploadFeature($file, $diskName, $product, $type, $info);
|
|
|
+ $this->updateFeature($file, $diskName, $product, $type, $info);
|
|
|
}
|
|
|
-
|
|
|
+ $product->update($data);
|
|
|
+ $product->categories()->sync($request->categories);
|
|
|
$msg = 'ویرایش محصول با موفقیت انجام شد ';
|
|
|
return redirect(route('products.index'))->with('success', $msg);
|
|
|
}
|
|
@@ -199,6 +200,7 @@ class ProductController extends Controller
|
|
|
'path' => $upload,
|
|
|
'mime_type' => $fileMimeType,
|
|
|
'extension' => $fileExtension,
|
|
|
+ 'parent_type' => 'packages\product',
|
|
|
'type' => $type,
|
|
|
'descriptionImg' => $info['featureDescription'],
|
|
|
'caption' => $info['featureCaption'],
|
|
@@ -261,6 +263,7 @@ class ProductController extends Controller
|
|
|
'path' => $upload,
|
|
|
'mime_type' => $fileMimeType,
|
|
|
'extension' => $fileExtension,
|
|
|
+ 'parent_type' => 'packages\product',
|
|
|
'type' => $type,
|
|
|
'descriptionImg' => $files['descriptionGallery'][$key],
|
|
|
'caption' => $files['captionGallery'][$key],
|