扩展包模型
Extending a package model
我已经安装了 Cmgmyr\Messenger,但是,我需要扩展 Thread 模型并可能需要扩展其他几个模型,因为我的用户 table 不包含 name
字段。
我需要扩展的方法是:
/**
* Generates a string of participant information
*
* @param null $userId
* @param array $columns
* @return string
*/
public function participantsString($userId=null, $columns=['name'])
{
$selectString = $this->createSelectString($columns);
$participantNames = $this->getConnection()->table('users')
->join('participants', 'users.id', '=', 'participants.user_id')
->where('participants.thread_id', $this->id)
->select($this->getConnection()->raw($selectString));
if ($userId !== null) {
$participantNames->where('users.id', '!=', $userId);
}
$userNames = $participantNames->lists('users.name');
return implode(', ', $userNames);
}
注意到 users.name 文件被调用了吗?这就是需要更改为用户名或更好的 users.firstname 和 users.lastname 在一起。
我需要将其扩展为以下结构:
Modules/
- Email/
- Models/
- Thread.php
我该怎么做?
最简单的方法是在 github 上分叉包,自己对包进行更改,然后在 composer 上引入自定义包(而不是原始包)。
通过这种方式,您可以控制对另一个包的更改。
具体拉叉方法如下:
How to require a fork with composer
我已经安装了 Cmgmyr\Messenger,但是,我需要扩展 Thread 模型并可能需要扩展其他几个模型,因为我的用户 table 不包含 name
字段。
我需要扩展的方法是:
/**
* Generates a string of participant information
*
* @param null $userId
* @param array $columns
* @return string
*/
public function participantsString($userId=null, $columns=['name'])
{
$selectString = $this->createSelectString($columns);
$participantNames = $this->getConnection()->table('users')
->join('participants', 'users.id', '=', 'participants.user_id')
->where('participants.thread_id', $this->id)
->select($this->getConnection()->raw($selectString));
if ($userId !== null) {
$participantNames->where('users.id', '!=', $userId);
}
$userNames = $participantNames->lists('users.name');
return implode(', ', $userNames);
}
注意到 users.name 文件被调用了吗?这就是需要更改为用户名或更好的 users.firstname 和 users.lastname 在一起。
我需要将其扩展为以下结构:
Modules/
- Email/
- Models/
- Thread.php
我该怎么做?
最简单的方法是在 github 上分叉包,自己对包进行更改,然后在 composer 上引入自定义包(而不是原始包)。
通过这种方式,您可以控制对另一个包的更改。
具体拉叉方法如下: How to require a fork with composer