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,
                ]);
            }
        }
    }
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,
                ]);
            }
        }
    }
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 , ] ) ; } } }
Upload and save the document to resource
@param $resource
@param $name
@param $filename
Upload and save the document to resource