I want to edit a package I pulled from composer in my Laravel 5 project, however i believe that if I ran composer update and a new version of this package has been released, I will lose all of my changes. How should I go about editing the package? Is there a way to copy package out of the vendor directory so I can use it somewhere else in my project?
The simple, fast and safe method:
first remove it from require
"require": {     "php": ">=5.6.4",     "laravel/framework": "5.3.*",     "laravelcollective/html": "^5.3.0", <==== remove this line                                "barryvdh/laravel-debugbar": "^2.3",     "doctrine/dbal": "^2.5" }, and then add it to autoload
"autoload": {     "psr-4": {         "App\\": "app/",         "Collective\\Html\\": "packages/laravelcollective/html/src", <==== add this line     }, } Please do not forget to run
composer dumpauto Alternative for step 3.
There is also a new alternative if you're using latest version of composer.
Add this to you composer.json
"repositories": [     {         "type": "path",         "url": "./packages/laravelcollective"     } ] And then modify the version of package to dev-master
"require": {     "php": ">=5.6.4",     "laravel/framework": "5.3.*",     "laravelcollective/html": "dev-master", <==== this line                                "barryvdh/laravel-debugbar": "^2.3",     "doctrine/dbal": "^2.5" }, Finally
composer update It actually isn't safe to edit composer packages, for the very reason you point out.
What I do is extends the classes that I want/need to change.
I have done it here with the Filesystem class. It doesn't ensure that it won't break, but it does let you update without overwriting your changes.
config/app.php
<?php  return [      'providers' => [  //        'Illuminate\Filesystem\FilesystemServiceProvider',         'MyApp\Filesystem\FilesystemServiceProvider',     ],      'aliases' => [         ...     ],  ]; MyApp\Filesystem\FilesystemServiceProvider.php
<?php namespace MyApp\Filesystem;  use Config; use Storage; use League\Flysystem\Filesystem; use Dropbox\Client as DropboxClient; use League\Flysystem\Dropbox\DropboxAdapter; use Illuminate\Filesystem\FilesystemManager as LaravelFilesystemManager;  class FilesystemManager extends LaravelFilesystemManager{      public function createDropboxDriver(array $config)     {         $client = new DropboxClient($config['token'], $config['app']);          return $this->adapt(             new Filesystem(new DropboxAdapter($client))         );     } } If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With