// Add a cover to the data if existing on the original entity
if ($entity->cover instanceof Image) {
- $tmpImgFile = tmpfile();
- $uploadedFile = $this->imageToUploadedFile($entity->cover, $tmpImgFile);
+ $uploadedFile = $this->imageToUploadedFile($entity->cover);
$inputData['image'] = $uploadedFile;
}
* Convert an image instance to an UploadedFile instance to mimic
* a file being uploaded.
*/
- protected function imageToUploadedFile(Image $image, &$tmpFile): ?UploadedFile
+ protected function imageToUploadedFile(Image $image,): ?UploadedFile
{
$imgData = $this->imageService->getImageData($image);
- $tmpImgFilePath = stream_get_meta_data($tmpFile)['uri'];
+ $tmpImgFilePath = tempnam(sys_get_temp_dir(), 'bs_cover_clone_');
file_put_contents($tmpImgFilePath, $imgData);
return new UploadedFile($tmpImgFilePath, basename($image->path));
'name' => ['required', 'string', 'max:255'],
'description' => ['string', 'max:1000'],
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
+ 'tags' => ['array'],
]);
$bookIds = explode(',', $request->get('books', ''));
'name' => ['required', 'string', 'max:255'],
'description' => ['string', 'max:1000'],
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
+ 'tags' => ['array'],
]);
if ($request->has('image_reset')) {
/** @var Book $copy */
$copy = Book::query()->where('name', '=', 'My copy book')->first();
+
$this->assertNotNull($copy->cover);
$this->assertNotEquals($book->cover->id, $copy->cover->id);
}