I'm using MySQL to store my data using PHP. In my table, I have two fields as date (Start_date and End_date). I'm having issue on those fields while saving the data. I gave the input as following
start_date: 2016-12-03 it saved as ---> 2192-12-03
I don't now what is the issue please anyone help in that.
sample code for inserting in cake php 3
$add_val= $this->school->newEntity();
$save_val= $this->school->patchEntity($add_val, $this->request->data);
if ($save = $this->school->save( $save_val))
{
$passmessage = ['status' => 'success];
}
school is the table name.
Related
I'm building a Laravel 9x application where i will need to populate some pages with the google places API.
Reading at the ToS of Google Places, i can only store in my db, for at most 30 days, the place_id.
Now, I'm facing an issue; I have a restaurants.index blade page where I'm showing in a table all the records from the restaurants table.
The issue is that i need to show in each table row the name of the restaurant that i don't have in my db table but i need to fetch it from Google Places Api.
So far, in my RestaurantsController I have done the following :
public function index()
{
$getAllRecords = Restaurant::all();
$google_places_api = new PlacesApi(env('GOOGLE_MAPS_API_KEY'));
$restaurants = new Collection();
foreach($getAllRecords as $restaurant){
$response= $google_places_api->placeDetails($restaurant->google_place_id);
$restaurant['name'] = $response['result']['name'];
$restaurants->prepend($restaurant);
}
dd($restaurants);//When dd here, the collection shows correctly the added value.
$restaurants->paginate(8);
$categories = Category::where('type', 'Restaurant')->cursor();
return view('tenant.restaurants.index', compact('categories', 'restaurants'));
}
And it seems to work pretty well if I dd($restaurants) inside the RestaurantsController as you can see from the picture below :
But when i try to #dd($restaurants) from the restaurants.index page, the added name is completely disappeared as you can see from the picture below :
It's now about a whole day that I'm tryng to understand why this behavior happen, is there anybody who has an idea of what is happening?
Thank you
My code is in PHP Laravel. And I tried to create a table in font-end which allow user to select my_date information from the drop-down calendar. Then, in back-end, I tied to save the table information into database via migration. But why the date information cannot be saved into mySQL database?
In config/database.php I already have
'strict' => false,
In index.blade.php file
<input id="my_date" type="text"
class=...
name="record[my_date]"
value="{{isset($project)&&isset($project->my_date)?$project->my_date->format('Y-m-d'):null}}"
placeholder="{{resolve('translate')->getWord('My Date')}}"
>
In migration
$table->dateTime('my_date');
I saw from this pots --> Date not being saved to mySQL datebase with laravel
And I tried --> I didn't get any error. Just when I delete & php artisan migrate & fill the font-end table again, there is still no date information being saved.
$table->dateTime('my_date')->format("Y-d-m");
I saw from this post --> After upgrade to laravel 5.3 error invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00'
And I tried --> no error, but still, no date information being saved.
$table->dateTime('pcmm_shipment_date')->default(NOW());
I also tried --> no error, but still, no date information being saved.
$table->datetime('expires_at')->nullable($value = true);
public function storeMyData(Request $request)
{
//validate
$validator = Validator::make($request['record'],
[
'project_id' => 'required',
'my_date' => 'required',
]
);
...
}
You can use useCurrent like so:
$table->timestamp('my_date')->useCurrent();
From the Laravel file vendor/laravel/framework/src/Illuminate/Database/Schema/ColumnDefinition.php it defines it as:
Set the TIMESTAMP column to use CURRENT_TIMESTAMP as default value
We are using Magento 1.9 for our application. Here is my sample code
$customer_collection= Mage::getModel("customer/customer")->load($data['customer_id']);
foreach ($data['data'] as $key => $customer) {
$customer_collection->setData($customer['attribute_name'] , $customer['attribute_value']);
}
$customer_collection->save(); //finally saving the data
Above code is working for all the fields except date field. Issue is when we send multiple data including date fields, other fields are getting updated but date field is not getting updated. Can anyone help me to solve this issue?
For date field update try to use
$object->setData($attributeCode, Varien_Date::now());
As #mladen-ilić Suggested,
I did Flush Cache Storage and tried again to post the data. It works like a charm.
I am trying to understand the use of different columns present in magento sales_flat_order table..
this is what i have got so far...
protect_code
used to ensure the order being loaded is the correct one for the guest's cookie value, but not sure why magento sets this field for even logged in users..
magento table "sales_flat_order" field "protect_code" explanation
Cancelled, Invoice, Refunded ...
discount_canceled, discount_invoiced, discount_refunded
shipping_amount, shipping_canceled, shipping_invoiced, shipping_refunded
shipping_tax_amount, shipping_tax_refunded
subtotal_canceled.....
tax_amount.....
total_canceled....
then again repeated for base_discount_canceled...
I already know everything with base has to do with base currency and the other is to with store currency..
Not able to understand need of so many columns discount_canceled, discount_invoiced, discount_refunded
Magento can issue partial refunds, so can understand for refunded..
but for invoice, canceled it can rather have only one field
eg. invoice = true and use grandtotal, basegrandtotal fields ..
if this was a design issue than why this is present even in magento 2?
If i am missing some feature of magento which requires this, then i am more than interested to know about it ..
edit_increment
edit_increment
relation_child_id, relation_child_real_id, relation_parent_id, relation_parent_real_id
I found this in app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
public function createOrder()
..
..
$oldOrder = $this->getSession()->getOrder();
$originalId = $oldOrder->getOriginalIncrementId();
if (!$originalId) {
$originalId = $oldOrder->getIncrementId();
}
$orderData = array(
'original_increment_id' => $originalId,
'relation_parent_id' => $oldOrder->getId(),
'relation_parent_real_id' => $oldOrder->getIncrementId(),
'edit_increment' => $oldOrder->getEditIncrement()+1,
'increment_id' => $originalId.'-'.($oldOrder->getEditIncrement()+1)
);
..
..
$this->getSession()->getOrder()->setRelationChildId($order->getId());
$this->getSession()->getOrder()->setRelationChildRealId($order->getIncrementId());
But i am not sure , for what condition this code is executed
Some old orders in the database are having edit_increment as 1....
Few other fields..
adjustment_negative , adjustment_positive , ext_customer_id , ext_order_id
P.S- Using magento enterprise..
I need to retrieve the birthday of a student from the database and set it as the birthday of a student entity. Then I need to load that data to a form.
$birth_day = strtotime($student_[0]['birthday']);
$birth__day = date('Y-m-d H:i:s',$birth_day);
$student->setBirthday($birth__day);
And in the form builder I have used the below code
add('birthday', 'birthday',array(
'data' => new \DateTime(),'placeholder'=>'-SELECT-'))
Instead of the birthday that particular student, it shows the today's date.
Can someone please explain what should I do to load the birthday instead of the today's date.
Thankyou in advance.
When you use the 'data' option, you are setting the default value for the field so in your example you are setting it to a new Datetime (today).
Here is the symfony doc page about it http://symfony.com/doc/current/reference/forms/types/form.html#data
Like #abdiel suggested, remove the data part.