ebess / advanced-nova-media-library

A Laravel Nova field for displaying, creating, updating and ordering a Spatie Media Library model.
591 stars 295 forks source link

Retrieving media of a model in Laravel Nova from another Laravel application #405

Open pkollarova opened 1 year ago

pkollarova commented 1 year ago

I have 2 Laravel apps - One that allows users to upload images to their profile and one that is used just as an admin panel (using Nova). Both admin and user app use the same database but they are on different websites/domains. Also both apps are on the same VPS.

Is it possible to retrieve images in the UserResource in the admin app from the user app?

I've tried approach like this but no luck:

In UserResource

Images::make('Documents', 'documents')
                        ->conversionOnIndexView('thumb')
                        ->fullSize()->enableExistingMedia(),

In User model

public function registerMediaCollections() : void {
        $this->addMediaCollection('document')
            ->useDisk('media');
    }

public function documents() {
        return $this->hasMany(Media::class, 'model_id')
            ->where('collection_name', 'document');
    }

In filesystem config

'media' => [
            'driver' => 'local',
            'root'   => parent_public_path('img/documents'),
            'url'    => env('PARENT_APP_URL').'/img/documents',
            'visibility' => 'public',
        ],

Function parent_public_path

function parent_public_path($path = '')
    {
        return '/var/www/userapp.myapp.com/public_html/public'.($path ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : $path);
    }

PARENT_APP_URL equals https://userapp.myapp.com