I'm using laravel 5.1 with eloquent, i have a postgre database and i would like to insert an object with some date in. My start format date is like '15/10/2015', and i need to convert into 'Y-m-d'.
For that i use date mutators in my model, i add this line :
protected $dates = ['created_at', 'updated_at', 'prj_start_date', 'prj_end_date_init'];
I use an architecture with services and repositories so in my repository for create my object in DB i have this :
$this->model->create($data);
When i try to insert i have this error
InvalidArgumentException in Carbon.php line 425:
Unexpected data found.
Unexpected data found.
Data missing
in Carbon.php line 425
at Carbon::createFromFormat('Y-m-d H:i:s', '15/10/2015') in Model.php line 2959
at Model->asDateTime('15/10/2015') in Model.php line 2915
at Model->fromDateTime('15/10/2015') in Model.php line 2870
at Model->setAttribute('prj_start_date', '15/10/2015') in Model.php line 422
Why isn't work, i've miss something ?
Can someone help me please ?
In at Carbon::createFromFormat('Y-m-d H:i:s', '15/10/2015') in Model.php line 2959 it is pretty clear that somehow laravel hardcoded it's dates mutator. I suggest using a manual approach, converting your string into Carbon instance via:
Carbon::createFromFormat($format, $time, $tz);
for example assuming have a date field instead of timestamp:
Carbon::createFromFormat('d/m/Y', '15/10/2015');
ps. i did not have the time to test this yet. Nevertheless, learning from the source is much interesting right?
ps. you might interested in changing laravel's format just like the docs however, i suspect this will affect created_at and updated_at (also deleted_at) fields that by default is a timestamp instead of dates.
ps. right, i do forget to mention you had to include Carbon to your controller, just add use Carbon/Carbon
I am going nuts here with Magento's import function. I have created one template product within my store and then exported it, so I can see what the attributes look like. Next I used Pentaho Data Integration to transform our suppliers product list into that format.
The header row contains, like the export, the service columns (starting with an underline). Here is one record of what my generated data looks like:
sku,_store,_attribute_set,_type,_category,_root_category,_product_websites,color,cost,country_of_manufacture,created_at,custom_design,custom_design_from,custom_design_to,custom_layout_update,description,gallery,gift_message_available,has_options,image,image_label,manufacturer,media_gallery,meta_description,meta_keyword,meta_title,minimal_price,msrp,msrp_display_actual_price_type,msrp_enabled,name,news_from_date,news_to_date,options_container,page_layout,price,required_options,short_description,small_image,small_image_label,special_from_date,special_price,special_to_date,status,tax_class_id,thumbnail,thumbnail_label,updated_at,url_key,url_path,visibility,weight,qty,min_qty,use_config_min_qty,is_qty_decimal,backorders,use_config_backorders,min_sale_qty,use_config_min_sale_qty,max_sale_qty,use_config_max_sale_qty,is_in_stock,notify_stock_qty,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,stock_status_changed_auto,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,_links_related_sku,_links_related_position,_links_crosssell_sku,_links_crosssell_position,_links_upsell_sku,_links_upsell_position,_associated_sku,_associated_default_qty,_associated_position,_tier_price_website,_tier_price_customer_group,_tier_price_qty,_tier_price_price,_group_price_website,_group_price_customer_group,_group_price_price,_media_attribute_id,_media_image,_media_lable,_media_position,_media_is_disabled
4053258104446,,Default,simple,"Schmuck/Halsschmuck",Default Category,base,,,,25.07.2015 20:06,,,,,"Collier, PVC, braun, 42 cm, Karabinerverschluss 925/- S, Durchmesser ca. 2 mm",,,0,"35416.jpg",,"JOBO",,,,,,,"Konfiguration verwenden","Konfiguration verwenden","Collier PVC braun, Verschluss aus 925 Silber 42 cm Karabiner ",,,"Artikelinformationsspalte",,5,0,"Collier PVC braun, Verschluss aus 925 Silber 42 cm Karabiner","no_selection",,,,,1,2,"no_selection",,2015/07/25 20:06:32.291,,,4,,,,1,0,0,1,1,1,0,1,1,,1,0,1,0,1,0,1,0,0,,,,,,,,,,,,,,,,,,,,,
Magento complains with:
Can not find required columns: sku
I just don't see what might be wrong with my data. Obviously the sku is there, and my DB is empty! Things I have checked:
File-Encoding is UTF-8
Tried with LR and CR/LF
Strings are surrounded by "
Which fields are manadatory for an import? I just coudn't find anything within the documentation.
I have spent timeless hours on this. Any help is greatly appreciated!
Check if your column names are exactly the same as database names -
Moreover, encoding should be UTF-8 without BOM
I am trying to update a Quickbase record via my Perl script. I am following the Perl API documentation: http://metacpan.org/pod/HTTP::QuickBase
The method used for editing a record is "EditRecord". As per this method, you cannot edit built-in fields which is true.
and I know that I am not modifying built-in field but an user-created field.
e.g. I want to modify the field called "OS" to "Windows"
So per the Perl modules CPAN documentation mentioned above, I do this:
my %new_record=$qb_obj->GetRecord($database_id, $record_id);
$new_record{"OS"}="Windows";
$qb_obj->EditRecord($database_id, $record_id, %new_record);
But I get following error:
The field named "Date Created" with field id 1 cannot be modified
Which basically means that I ma trying to modify the field "Date Created" with Field ID "1". However, I am not doing that. It might be pulling that parameter some how. THe perl as well as the Quickbase documentation is not helping much.
Here is the Quickbase API documentation: http://www.quickbase.com/api-guide/edit_record.html#Overview
Can someone help me on this.
thanks.
Since you already know the id of the record, you don't need to read the record before modifying it. You should be able to just remove your first line, create the %new_record without reading it from QB, then your 2nd and 3rd lines should work fine.
The alternative is to remove the built-in QB fields from %new_record before doing the EditRecord.