octobercmsoctober-form-controller

October export file url to database


Is there a way to export the url of a file in October to a database table? I currently have a model called "Image" that stores the url by doing the following:

public $attachOne = [
  'image' => ['System\Models\File']
];

I'm storing other attributes in the model list (called columns.yaml) and in the database, I'd like to add the url here if possible?

columns:
  id:
    label: ID
    type: number
  name:
    label: Name
    type: text
    searchable: true
    sortable: true

Solution

  • Its relatively easy, you just need to add Accessor

    In your modal add this Accessor

    public function getImagePathAttribute() {
        return $this->image->path;
    }
    

    And in your modal's columns

    columns:
      id:
        label: ID
        type: number
      name:
        label: Name
        type: text
        searchable: true
        sortable: true
      image_path:
        label: Image Path
        type: text
    

    Now it will show the image's path as a column and you can export its value.

    enter image description here

    if any doubt please comment.