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

leocavalcante
leocavalcante

Hi, I'm using the ImportExportBehaviour and sets a custom form fields at export configuration. In there I have to datepickers "created_at_from" and "created_at_to", my idea was to use them to filter the export by a daterange:

$query = Lead::query();

if ($this->created_at_from) {
    $query->where('created_at', '>=', $this->created_at_from);
}

if ($this->created_at_to) {
    $query->where('created_at', '<=', $this->created_at_to);
}

$leads = $query->get();

But this options are being used by the query I guess, because of the error: "created_at_from" on line 404 of C:\path\to\project\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php Since there is no "created_at_from" column, just the "created_at" from timestamps.

In fact, just take a look at: https://github.com/octobercms/october/blob/master/modules/backend/behaviors/ImportExportController.php#L390 Its filling the Model with the ExportOptions, no matter what ExportOptions are.

Possible bug or am I doing something wrong?

leocavalcante
leocavalcante

Wow, got it.

Have traced down then I found what causes the error, it was a MassAssignmentException: https://github.com/laravel/framework/blob/5.0/src/Illuminate/Database/Eloquent/Model.php#L404

Keys wasn't fillable so for my surprise I does need to add: protected $fillable = array('created_at_from', 'created_at_to'); to my export model. That is not documented at: https://octobercms.com/docs/backend/import-export#custom-options :/

Thanks!

Alexa94
Alexa94

Thank you! It works!

Igor Jacaúna
Igor Jacaúna

Great! Thank you! It works!

Igor Jacaúna
Igor Jacaúna

manrox.drag17392 said:

Igor Jacaúna said:

Great! Thank you! It works!

can you share how you achieved it

https://octobercms.com/forum/post/custom-export-options-are-being-used-by-the-query?page=1#post-9966

1-5 of 5

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