Ad

October Export File Url To Database

- 1 answer

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
Ad

Answer

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.

Ad
source: stackoverflow.com
Ad