I use the following code to inser data in table:
$order = new OrderProduct();
$order->save([
"created_at" => Carbon::now(),
"user_id" => $user->id,
"note" => $request->note
]);
Model OrderProduct
is:
class OrderProduct extends Model
{
public $timestamps = true;
protected $table = "class OrderProduct extends Model
{
public $timestamps = true;
protected $table = "order_product";
protected $fillable = [
'order_id', 'status', 'user_id', 'note'
];";
protected $fillable = [
'order_id', 'status', 'user_id', 'note'
];
}
Why I always get user_id
is equal 0 in table order_product
?
I tried also replace $user->id
to real value :
$order->save([
"created_at" => Carbon::now(),
"user_id" => 2,
"note" => $request->note
]);
But again get zero value in this field.
Type of user_id
is:
| user_id | int(11) | NO | | NULL
Try adding it this way:
By default Laravel adds the timestamp to the created_at and updated_at columns.
Let me know if that works.