How to properly add a title to an uploaded file.
Created 6 years ago by gonziis

I upload files like this

$contents = "";
while(empty($contents)){
         $contents = @file_get_contents($url);
 }
$attachment = Storage::put("pielikumi/".$value2->path,$contents);

I tried to $attachment->getEntry()->title = "test" but it showed an error Creating default object from empty value

Also just tried $attachment->title = "test" showed no error, but the actual titles were not changed when I checked in DB and actually in the interface.

By the way, this is a code for a seeder, at the top I truncate all tables and delete the directory, then it downloads the content and uploads it, but I also want to migrate the custom titles as there is a Title field available for every file in PyroCMS.

ryanthompson  —  6 years ago

What is attachment? A file interface? I can't recall sorry :-/

If you do something like $file->title = 'Foo' then you need to run $file->save() or using a repository $files->save($file).

Hope this helps!