This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

phplee
phplee

Im a newbie to October and have create a export using Octobers documentation which works fine. However i need to add a date 'from' and 'to' to the export form so i can export based on create_at field.

If anyone could please help me would much appreciate it.

thanks

philipptempel
philipptempel

Meaning you want to limit the range of data that is being exported? Please read the docs which has a very nice example on how to extend the export form with custom fields. And it also shows how and where you can use the submitted form data to export your data.

phplee
phplee

thanks will have a look now!

phplee
phplee

Can i just ask another quick question.

I need to format create_at date for the exported. Is this done in the exported column.yaml file?

thanks again

philipptempel
philipptempel

If your created_at column is registered as a timestamp in the model then it should be converted to a Carbon-instance when retrieved from the database. Once the model is exported, it will be converted according to the configuration of Carbon. You can, however, provide a method in your export model that mutates the created_at attribute see the docs. Otherwise, just give it a try and see how it turns out to be exported without any manual adjustments first.

phplee
phplee

Hi Philipp

Sorry to be a pain but i can't get the created_at to format. I basically need it to be d/M/Y

Model:

protected $dates = ['created_at', 'updated_at'];

public function setCreatedAtAttribute($value) { $this->attributes['created_at'] = $value->format('d/M/Y'); }

Export Columns

columns:

title: TITLE
firstname: FORENAME
lastname: SURNAME
address1: ADDRESS1
address2: ADDRESS2
address3: ADDRESS3
address4: ADDRESS4
city: TOWN
county: COUNTY
country: COUNTRY
postcode: POSTCODE
telephone: TELEPHONE NO
email: E-MAIL
ga_declaration: GA DECLARATION
opt_in: MAILING YN
amount: DONATION AMOUNT
created_at: DONATION DATE
comment: DONATION MEMO
iro_mess: IRO MESS

Any help would be great pal

Last updated

philipptempel
philipptempel

How does your export model look like? Does it possibly have a line that reads...

public $timestamps = false;

Also, it should be

public function getCreatedAtAttribute($value) {
    return $value->format('d/M/Y');
}

Last updated

phplee
phplee

Thanks for the reply really appreciate it.

i don't have this in my model

public $timestamps = false;

ive added:

public function getCreatedAtAttribute($value) {
return $value->format('d/M/Y'); }

Now im getting this error. created at must not be a Carbon Object

Call to a member function format()

Last updated

phplee
phplee

Ive managed to do it this was:

public function getCreatedAtAttribute($value)
{
    //return $value->format('d/M/Y');
    return Carbon::parse($value)->format('d/m/Y');
}

Last updated

phplee
phplee

Thank you for your help. Can i ask one more question. Im using a from_date and to_date to select a date range based on the created_at. The problem is because created_at is of datetime the to_date is not inclusive.

See below

 $result = Self::IsComplete($this->is_complete)
        ->IsLive($this->is_live)
        ->whereBetween('created_at', array($this->from_date, $this->to_date))
        ->orderBy('created_at', 'asc')
        ->get()
        ->toArray();

How can i include the to_date?

thanks

Last updated

phplee
phplee

Just for anyone else with this problem i solved the problem by adding a day to the to_date. Probably not the best solution but it works.

 $toDate = Carbon::parse($this->to_date)->addDays(1);

    $result = Self::IsComplete($this->is_complete)
        ->IsLive($this->is_live)
        ->whereBetween('created_at', array($this->from_date, $toDate))
        ->orderBy('created_at', 'asc')
        ->get()
        ->toArray();

1-11 of 11

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.