Search code examples
laravelpdomediamedia-librarylaravel-medialibrary

Laravel - Publish Vendor Class Spatie\MediaLibrary\Models\Media in Spatie to configure it with MongoDB


here i have a Media class at Spatie\MediaLibrary\Models\Media path. it was creating PDO issues with this code.

class Media extends Model implements Responsable, Htmlable

so i tried this in there and it worked for the cause.

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class Media extends Eloquent implements Responsable, Htmlable

now its fine as long its working but what about updating composer will remove everything i guess and PDO problem will appear again. so how can i publish it out there to make it permanent?


Solution

  • I think you best bet here would be to fork the spatie/laravel-medialibrary repository. You can then make your changes in your fork and commit them. Then you'll be able to use your commit as the package version in your composer.json and your fork as the repository.

    For example in your composer.json change your spatie/laravel-medialibrary requirement to "spatie/laravel-medialibrary": "dev-{your-branch-name}#{your commit hash}",. And add a "repositories" field to your composer.json like this:

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/{your github username}/laravel-medialibrary"
        }
    ]
    

    Have a look at this StackOverflow question for more examples on how to use your own commit in your package. Also have a look at Composer's "Repositories" documentation to see other ways to add repositories (for example to use a local path) and their "Versions#Branches" documentation to see how to specify branches as versions.