L
L
lynnikvadim2015-09-24 09:38:56
Laravel
lynnikvadim, 2015-09-24 09:38:56

How to change data in a large number of models?

There is a code $Org= OrgModel::all();
This code receives data from the fields name, org, order_data.
The field order_datais a date and time (i.e. like this: 0000-00-00 00:00:00 )
How do I change the date format to be 25-12-2015.
Is it possible?
With the help of carbon, you can change one record ( ::find(id);)
Or am I misunderstanding something?!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2015-09-24
@alexey-m-ukolov

laravel.com/docs/5.1/eloquent-mutators#date-mutators

D
Dmitry Evgrafovich, 2015-09-24
@Tantacula

Well, if you need to change the field itself in the database, then climb into the database and set the date field type, if you need to change the output, then you need to laravel.com/docs/5.1/eloquent-mutators#accessors-a...

public function getOrderDataAttribute($value) {
 return $value->toDateString();  
}

I could be wrong and $value would first need to be converted to a carbon object in order to apply this method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question