-
app/Http/Controllers/Admin/ProductController.php
Open in GitHubuse App\Product; use App\Http\Requests\Product\CreateProductRequest; class ProductController extends Controller { // public function store(CreateProductRequest $request) { $product = Product::create([ 'name' => $request->name, 'description' => $request->description, 'code' => $request->code, 'price' => $request->price, 'is_new' => $request->is_new, 'on_sale' => $request->on_sale, 'quantity' => $request->quantity, 'category_id' => $request->category_id, 'sub_category_id' => $request->sub_category_id, 'meta_keywords' => $request->meta_keywords, 'meta_description' => $request->meta_description, 'slug' => Str::slug($request->name), ]); // $product->attributes()->createMany( collect($request->attribute_name) ->map(function ($name, $index) use ($attributeValues) { return [ 'attribute_name' => $name, 'attribute_value' => $attributeValues[$index], ]; }) ); // } // }