so i am trying to override laravel-medialibrary so that when i run
$modelA
->addMedia($attachment)
->withCustomProperties(['model_id' => $modelA->id])
->toMediaCollection('attachments_a');
, it adds a record into another specified database eg: database1_mysql
However, it is now currently adding into my current database(database2) instead..
I have created a Media model which has a connection already to another database
namespace App\Domains\Test\Models\Media;
class Media extends Model
{
protected $connection = 'database1_mysql';
}
And the model im relating the media to, i also have overriden the relationship to refer to the media that is connected to another table.
use App\Domains\Test\Models\Media;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class ModelA extends Model implements HasMedia
{
use InteractsWithMedia;
public function media(): MorphMany
{
return $this->morphMany(Media::class, 'model');
}
}