|
@@ -75,15 +75,16 @@ class ProductController extends Controller
|
|
|
// *********************************************************save products ******************
|
|
|
public function store(ProductRequest $request)
|
|
|
{
|
|
|
+// dd($request->all());
|
|
|
$request->merge([
|
|
|
'price' => preg_replace('/[^0-9]+/', '', $request->price),
|
|
|
'sale_price' => preg_replace('/[^0-9]+/', '', $request->sale_price),
|
|
|
]);
|
|
|
-// dd($request->all());
|
|
|
if (!$request->has('draft_id')) {
|
|
|
return abort(403, 'دسترسی به این صفحه ممکن نیست ؛ لطفا مجددا تلاش کنید.');
|
|
|
}
|
|
|
$draft = Draft::findOrFail($request->draft_id);
|
|
|
+// $info = $request->only(['featureDescription', 'featureCaption']);
|
|
|
$data = [
|
|
|
'title' => $request->title,
|
|
|
'slug' => $request->slug,
|
|
@@ -94,7 +95,9 @@ class ProductController extends Controller
|
|
|
'type' => $request->type,
|
|
|
'status' => $request->status,
|
|
|
'discription' => $request->discription,
|
|
|
- 'creator_id' => auth()->user()->id
|
|
|
+ 'creator_id' => auth()->user()->id,
|
|
|
+// 'descriptionImg' => $request->featureDescription,
|
|
|
+// 'caption' => $request->featureCaption,
|
|
|
];
|
|
|
// if( $draft->attachments->count() == 0 ){
|
|
|
// return redirect()->back()
|
|
@@ -105,16 +108,11 @@ class ProductController extends Controller
|
|
|
$product = Product::create($data);
|
|
|
$product->categories()->sync($request->categories);
|
|
|
|
|
|
- Upload::where('parent_type', 'Packages\Product')->where('uploadable_id', $draft->id)
|
|
|
+ Upload::where('parent_type', 'Packages\Product')->where('uploadable_id', $draft->id)->where('uploadable_id', $draft->id)
|
|
|
->update(['parent_type' => 'image\Product', 'uploadable_id' => $product->id]);
|
|
|
$draft->delete();
|
|
|
+// $uploaded = Upload::create();
|
|
|
|
|
|
- if ($request->has('gallery_image')) {
|
|
|
- $file = $request->only('gallery_image', 'captionGallery', 'descriptionGallery');
|
|
|
- $type = 'gallery_image';
|
|
|
- $diskName = 'product';
|
|
|
- $this->uploadGallery($file, $diskName, $product, $type);
|
|
|
- }
|
|
|
|
|
|
$msg = 'ذخیره محصول با موفقیت انجام شد ';
|
|
|
return redirect(route('products.edit', $product->id))->with('success', $msg);
|
|
@@ -178,8 +176,7 @@ class ProductController extends Controller
|
|
|
public function uploadFeature(Request $request)
|
|
|
{
|
|
|
if ($request->has('featured_image')) {
|
|
|
-
|
|
|
- $info = $request->only(['featureDescription', 'featureCaption']);
|
|
|
+ $info = $request->only(['featureDescription', 'featureCaption']);
|
|
|
$file = $request->file('featured_image');
|
|
|
$type = 'featured_image';
|
|
|
$diskName = 'product';
|
|
@@ -206,9 +203,10 @@ class ProductController extends Controller
|
|
|
'descriptionImg' => $info['featureDescription'],
|
|
|
'caption' => $info['featureCaption'],
|
|
|
];
|
|
|
+ $uploaded = Upload::create($uploadData);
|
|
|
}
|
|
|
|
|
|
- $uploaded = Upload::create($uploadData);
|
|
|
+ dd($uploadData);
|
|
|
|
|
|
// $uploaded = $product->uploads()->create($uploadData);
|
|
|
}
|
|
@@ -249,9 +247,15 @@ class ProductController extends Controller
|
|
|
}
|
|
|
|
|
|
// ****************************uploadGallery********************
|
|
|
- public function uploadGallery($files, $diskName, $product, $type)
|
|
|
+ public function uploadGallery(Request $request)
|
|
|
{
|
|
|
- foreach ($files['gallery_image'] as $key => $file) {
|
|
|
+
|
|
|
+ if ($request->has('gallery_image')) {
|
|
|
+ $files = $request->only('gallery_image', 'captionGallery', 'descriptionGallery');
|
|
|
+ $type = 'gallery_image';
|
|
|
+ $diskName = 'product';
|
|
|
+// dd($files);
|
|
|
+ foreach ($files['gallery_image'] as $key => $file) {
|
|
|
$fileExtension = $file->getClientOriginalExtension();
|
|
|
$fileMimeType = $file->getMimeType();
|
|
|
$afterDiskRoot = '/' . jdate()->format('Y') . '/' . jdate()->format('m');
|
|
@@ -261,19 +265,26 @@ class ProductController extends Controller
|
|
|
if (File::exists($filePath)) {
|
|
|
$fileName = time() . '_' . $fileName;
|
|
|
}
|
|
|
+ $draft = Draft::orderBy('id', 'Desc')->get()->first();
|
|
|
$upload = $file->storeAs($afterDiskRoot, $fileName, $diskName);
|
|
|
+
|
|
|
$uploadData = [
|
|
|
'name' => $fileName,
|
|
|
'path' => $upload,
|
|
|
'mime_type' => $fileMimeType,
|
|
|
'extension' => $fileExtension,
|
|
|
'parent_type' => 'packages\product',
|
|
|
+ 'uploadable_type' => 'Packages\Product\Models\Product',
|
|
|
+ 'uploadable_id' => $draft->id,
|
|
|
'type' => $type,
|
|
|
'descriptionImg' => $files['descriptionGallery'][$key],
|
|
|
'caption' => $files['captionGallery'][$key],
|
|
|
];
|
|
|
- $uploaded = $product->uploads()->create($uploadData);
|
|
|
+// dd($uploadData);
|
|
|
+ $uploaded = Upload::create($uploadData);
|
|
|
+
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function updateGallery($files, $diskName, $product, $type)
|