This commit is contained in:
Kevin Adametz 2020-01-02 19:22:30 +01:00
parent f03862b523
commit 1a43060996
42 changed files with 1160 additions and 83 deletions

View file

@ -7,6 +7,7 @@ namespace App\Repositories;
use App\Models\Product;
use App\Models\ProductAttribute;
use App\Models\ProductCategory;
use App\Models\ProductImage;
class ProductRepository extends BaseRepository {
@ -84,6 +85,57 @@ class ProductRepository extends BaseRepository {
}
public function copy($model)
{
$this->model = $model->replicate();
$this->model->name = "Kopie: ".$this->model->name;
$this->model->save();
//categories
foreach ($model->categories as $category){
ProductCategory::create([
'product_id' => $this->model->id,
'category_id' => $category->category_id,
]);
}
//attributes
foreach ($model->attributes as $attribute){
ProductAttribute::create([
'product_id' => $this->model->id,
'attribute_id' => $attribute->attribute_id,
]);
}
//images
foreach ($model->images as $image){
$name = \App\Services\Slim::sanitizeFileName($image->original_name);
$name = uniqid() . '_' . $name;
//copy
$data = \Storage::disk('public')->copy(
'images/product/'.$image->product_id.'/'.$image->filename,
'images/product/'.$this->model->id.'/'.$name
);
ProductImage::create([
'product_id' => $this->model->id,
'filename' => $name,
'original_name' => $image->original_name,
'ext' => $image->ext,
'mine' => $image->mine,
'size' => $image->size
]);
}
return $this->model;
}
public function delete()