Reputation: 386
its very suspect. I have an array with values. But when I use a create method on the model the values are NULL. When I use the update function all values are right.
protected function createProduct(array $data)
{
// dd($data['category_id']);
return Product::create([
'category_id' => $data['category_id'],
'manufacturer_id' => $data['manufacturer_id'],
'sku' => $data['sku'],
'collection' => $data['collection'],
'name' => $data['name'],
'name_en' => $data['name_en'],
'sku_supplier' => $data['sku_supplier'],
'order' => $data['order'],
]);
//
Upvotes: 1
Views: 659
Reputation: 163768
create()
is using mass assignment feature so you need to add all values to the $fillable
property first which should be added to Product
model:
class Product extends Model
{
protected $fillable = ['category_id', 'manufacturer_id', 'sku', 'collection', 'name', 'name_en', 'sku_supplier', 'order'];
Also, you can just do this to create new product:
return Product::create($data);
Upvotes: 2