Skip to main content

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

Read more here

krayin/laravel-crm

20233 stars
2 code files
View krayin/laravel-crm on GitHub

packages/Webkul/Product/src/Repositories/ProductRepository.php

Open in GitHub
use Illuminate\Container\Container;
use Webkul\Core\Eloquent\Repository;
use Webkul\Attribute\Repositories\AttributeValueRepository;
 
class ProductRepository extends Repository
{
protected $attributeValueRepository;
 
public function __construct(
AttributeValueRepository $attributeValueRepository,
Container $container
)
{
$this->attributeValueRepository = $attributeValueRepository;
 
parent::__construct($container);
}
 
public function create(array $data)
{
$product = parent::create($data);
 
$this->attributeValueRepository->save($data, $product->id);
 
return $product;
}
//
}

packages/Webkul/Admin/src/Http/Controllers/Product/ProductController.php

Open in GitHub
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Attribute\Http\Requests\AttributeForm;
use Webkul\Product\Repositories\ProductRepository;
 
class ProductController extends Controller
{
protected $productRepository;
 
public function __construct(ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
 
request()->request->add(['entity_type' => 'products']);
}
//
public function store()
{
Event::dispatch('product.create.before');
 
$product = $this->productRepository->create(request()->all());
 
Event::dispatch('product.create.after', $product);
 
session()->flash('success', trans('admin::app.products.create-success'));
 
return redirect()->back();
}
//
}

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.