0

我正在使用 Compoships 包使 Laravel 支持多键关系,但我想覆盖这个包中的特征函数。

这是当前的流程:

我在我的项目中使用的主要特征使用了包中的另一个,它使用了另一个(我想要覆盖的那个)

public function addConstraints()
{
    if (static::$constraints) {
        $foreignKey = $this->getForeignKeyName();
        $parentKeyValue = $this->getParentKey();

        //If the foreign key is an array (multi-column relationship), we adjust the query.
        if (is_array($this->foreignKey)) {
            foreach ($this->foreignKey as $index => $key) {

                /*list(, $key) = explode('.', $key);
                $fullKey = $this->getRelated()->getTable().'.'.$key;*/

                $keyPortions = explode('.', $key);
                if(count($keyPortions) === 2)
                    $fullKey = $this->getRelated()->getTable() . '.' . $key;
                else
                    $fullKey = $key;

                $this->query->where($fullKey, '=', $parentKeyValue[$index]);
                $this->query->whereNotNull($fullKey);
            }
        } else {
            $fullKey = $this->getRelated()->getTable().'.'.$foreignKey;
            $this->query->where($fullKey, '=', $parentKeyValue);
            $this->query->whereNotNull($fullKey);
        }
    }
}

我能够在本地覆盖它,但是一旦我部署代码(发生作曲家更新),我就会丢失我的修改

所以我该怎么做?

4

1 回答 1

0

简单只需在您使用它的控制器中创建一个具有相同名称的公共函数

它自动覆盖

例如

我们知道在 auth 文件夹注册控制器中有一个特征 RegistersUSers;这个 trait 包含一个函数 authenticate 所以如果我们想覆盖它。只需创建一个同名的公共函数

class RegisterController extends Controller
{

    use RegistersUsers;

   public function authenticate(){

   }
于 2019-03-05T09:18:19.230 回答