In my laravel project i need to add multiple records at a time an i also want to insert the created_at and updated_at as works in save() automatically.But not working in insert method.
for($i=0; $i<count($req->location_id); $i++)
{
$asset_arr[$i]['property_id'] = $this->id;
$asset_arr[$i]['location_id'] = $req->location_id[$i];
$asset_arr[$i]['model_id'] = $req->model_id[$i];
$asset_arr[$i]['appliance_owner'] = $req->appliance_owner[$i];
$asset_arr[$i]['current'] = $req->current[$i];
if($req->installdate[$i]!=''){
$asset_arr[$i]['installdate'] = date('Y-m-d',strtotime($req->installdate[$i]));
}
$asset_arr[$i]['comment'] = $req->comment[$i];
}
if(!empty($asset_arr)){
Asset::insert($asset_arr);
}
insert()
is not an Eloquent method, so you'll need to add timestamps manually. Do something like this:
$asset_arr[$i]['created_at'] = Carbon::now();
$asset_arr[$i]['updated_at'] = Carbon::now();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With