Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Loydtafireyi/ZimCart-Laravel-Ecommerce

213 stars
1 code files
View Loydtafireyi/ZimCart-Laravel-Ecommerce on GitHub

app/Http/Controllers/Admin/ProductController.php

Open in GitHub
use 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],
];
})
);
//
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.