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?

推荐答案

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))
        );
    }
}

Laravel相关问答推荐

未将Laravel Blade属性传递给组件或类

LaravelEloquent 的模型如何将值从控制器内部的函数传递到Render()

模型文件名更改数据库中的表名

Laravel 获取具有多对多关系的中间表数据

assertSee 由于 html 代码中的空格而失败

自从 Laravel 使用 Vite 更新后,我无法运行npm run dev

当使用Laravel eloquent查询100000条数据时速度很慢

FileViewFinder.php 第 137 行中的 Laravel 5 InvalidArgumentException:未找到视图 [.admin]

Laravel 5.2 无法打开 laravel.log

在 laravel 中动态更改时区

Laravel 5.1 重命名项目

Laravel 初学者的良好开端

如何在 Laravel 5 中按键获取所有缓存项目的列表?

laravel 5.1 在没有 VM 重启的情况下看不到作业(job)文件的更改

Laravel League/flysystem 使用 AWS S3 获取文件 URL

Laravel 获取文件内容

Laravel 仓库

登录后 DevTools 无法解析 SourceMap 错误将重定向到该 js 文件

Laravel 手动登录功能

Laravel 5.3 - 用户Collection 的单一通知(关注者)