protected function createOrUpdateDocument($resource, $name, $filename)
    {
        if (request()->hasFile('file')) {

            // create or update
            if (is_null($resource->document)) {
                $resource->documents()->create([
                    'name'     => $name,
                    'filename' => $filename,
                ]);
            }
            else {
                // update the document entry
                $resource->document->update([
                    'name'     => $name,
                    'filename' => $filename,
                ]);
            }
        }
    }