我使用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
之后?