Hi, I’ve been trying to figure out how to update a files field programmatically.
I couldn’t find “the correct way” anywhere, so here’s what I’m trying to do after the files is moved into the page content folder:
$page->update([ 'modelfile' => $page->files()->sortBy('modified', 'desc')->limit(1), ]);
This code works, however it ONLY works when there’s already a file in the content folder. So first time uploading a file it does not save a file to the field, but the next time it does.
How should I go about solving this?