为什么方法addMedia()重设属性?

时间:2019-04-08 11:30:29

标签: laravel

我使用library。创建了自定义路径生成器:

class FilePathGenerator implements PathGenerator {
  public function getPath(Media $media) : string {
    return $media->model->getDirectory();
  }
  public function getPathForConversions(Media $media) : string {
    return $this->getPath($media) . 'conversions/';
  }
  public function getPathForResponsiveImages(Media $media): string {
    return $this->getPath($media).'/responsive/';
  }
}

在控制器中:

$client = Client::find($client_id)
$client->setCounterpartyDirectory(145);
SaveData::saveData( $client, 'client');

和班级:

class SaveData {

  public static function saveData( $model, string $collectionName ) {

    $temp = tmpfile();

    fwrite($temp, json_encode('test'));

    $model->addMedia(stream_get_meta_data($temp)['uri'])->toMediaCollection($collectionName);
    fclose($temp);
    return $model;
  }
}

在模型中:

 protected $counterpartyFolder = false;

为什么在使用方法 addMedia() $this->counterpartyFolder; // 145之前和$this->counterpartyFolder; // false之后?

0 个答案:

没有答案