|
@@ -5,6 +5,8 @@ namespace Packages\Product\Http\Controllers;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use Facade\Ignition\Support\Packagist\Package;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
+use Illuminate\Support\Facades\Facade;
|
|
|
+use Illuminate\Support\Facades\File;
|
|
|
use Packages\Product\Http\Requests\ProductRequest;
|
|
|
use Packages\Product\Models\Product;
|
|
|
use Illuminate\Http\Request;
|
|
@@ -97,8 +99,11 @@ class ProductController extends Controller
|
|
|
{
|
|
|
|
|
|
$categories = Category::orderBy('id', 'DESC')->get();
|
|
|
- $upload = upload::orderBy('id', 'DESC')->get();
|
|
|
- return view('product::product.edit', compact('product', 'categories', 'upload'));
|
|
|
+ $uploads = Upload::orderBy('id', 'DESC')->get();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return view('product::product.edit', compact('product', 'categories', 'uploads'));
|
|
|
}
|
|
|
|
|
|
// *******************************************update page product*****************************************
|
|
@@ -121,17 +126,25 @@ class ProductController extends Controller
|
|
|
'type' => $request->type,
|
|
|
'status' => $request->status,
|
|
|
'discription' => $request->discription,
|
|
|
- 'creator_id' => auth()->user()->id
|
|
|
- ];
|
|
|
+ 'creator_id' => auth()->user()->id,
|
|
|
|
|
|
- $product->update($data);
|
|
|
+ ];
|
|
|
+ $product->save($data);
|
|
|
|
|
|
$product->categories()->sync($request->categories);
|
|
|
+ if ($request->has('photo')) {
|
|
|
+ $file = $request->file('photo');
|
|
|
+ $diskName = 'product';
|
|
|
+ $this->uploader($file, $diskName, $product);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
$msg = 'ویرایش محصول با موفقیت انجام شد ';
|
|
|
- dd($request->all());
|
|
|
- return redirect(route('products.index'),compact('upload'))->with('success', $msg);
|
|
|
+
|
|
|
+ return redirect(route('products.index'))->with('success', $msg);
|
|
|
}
|
|
|
|
|
|
//***************************** delete products*****************************************
|
|
@@ -147,7 +160,9 @@ class ProductController extends Controller
|
|
|
|
|
|
public function uploader($file, $diskName, $product)
|
|
|
{
|
|
|
+
|
|
|
$fileExtension = $file->getClientOriginalExtension();
|
|
|
+
|
|
|
$fileMimeType = $file->getMimeType();
|
|
|
|
|
|
$afterDiskRoot = '/' . jdate()->format('Y') . '/' . jdate()->format('m');
|
|
@@ -156,7 +171,7 @@ class ProductController extends Controller
|
|
|
|
|
|
$filePath = storage_path('app/public/' . $diskName . $afterDiskRoot . '/' . $fileName);
|
|
|
|
|
|
- if (File_exists($filePath)) {
|
|
|
+ if (File::exists($filePath)) {
|
|
|
$fileName = time() . '_' . $fileName;
|
|
|
}
|
|
|
|
|
@@ -171,22 +186,13 @@ class ProductController extends Controller
|
|
|
|
|
|
];
|
|
|
|
|
|
+
|
|
|
$uploaded = $product->uploads()->create($uploadData);
|
|
|
- dd($uploaded);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
-// public function serveFile(Request $request, $id)
|
|
|
-// {
|
|
|
-// $attachment = Upload::where('uploadable_type', 'Packages\Product\Models\Product')
|
|
|
-// ->where('id', $id)
|
|
|
-// ->firstOrFail();
|
|
|
-//
|
|
|
-// if (!\Storage::disk('product')->exists($attachment->path))
|
|
|
-// abort(404);
|
|
|
-// $file_path = \Storage::disk('product')->getDriver()->getAdapter()->getPathPrefix() . $attachment->path;
|
|
|
-//
|
|
|
-// return response()->file($file_path);
|
|
|
-// }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|