haizone's avatar

use laravel-medialibrary with tenancy

i try to work with laravel-medialibrary and tenancyforlaravel

but its didnt work i work with 1 db

when i try a simple upload its upload to: storage/app/{media_number} media_number is like: 1,2 3,4 ...

but its need to put the image in tenant folder

and when i try to custome like this

<?php
namespace App\MediaLibrary;

use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\MediaLibrary\Support\PathGenerator\DefaultPathGenerator;

class InfyCRMMediaPathGenerator extends DefaultPathGenerator
{
    
    protected function getBasePath(Media $media): string
    {
        dd(tenant('id'));
        return tenant('id').DIRECTORY_SEPARATOR.$media->getKey();
    }
}

i didnt get the tenant('id')

plz help how to make it work with tenant

update: i do that i didnt think is the best answer

    protected function getBasePath(Media $media): string
    {
        $model = $media->model()->first();

        return $model->tenant_id;
    }

thanks

0 likes
0 replies

Please or to participate in this conversation.