Compare commits
No commits in common. "424ca30932610dcef496640e4097644ed404f13b" and "77cfe9bbc7a11ee6494b205458ac5c75ff5c166d" have entirely different histories.
424ca30932
...
77cfe9bbc7
|
@ -29,9 +29,9 @@ class DeferredMediaData extends Data
|
|||
]);
|
||||
}
|
||||
|
||||
public static function collectionFromPaths(Collection $paths, MediaCollection $collection): Collection
|
||||
public static function collectionFromPaths(Collection $paths, MediaCollection $collection): DataCollection
|
||||
{
|
||||
return static::collect($paths->map(fn ($path) => static::fromPath($path, $collection)));
|
||||
return static::collection($paths->map(fn ($path) => static::fromPath($path, $collection)));
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
|
|
|
@ -5,8 +5,6 @@ namespace Zoomyboy\MedialibraryHelper;
|
|||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Collection;
|
||||
use Spatie\Image\Image;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
use Spatie\MediaLibrary\MediaCollections\Exceptions\InvalidBase64Data;
|
||||
|
@ -68,7 +66,7 @@ class MediaController
|
|||
|
||||
$collection->runCallback('after', $model->fresh());
|
||||
|
||||
return $isSingle ? MediaData::from($medias->first()) : response(MediaData::collect($medias), 201);
|
||||
return $isSingle ? MediaData::from($medias->first()) : MediaData::collection($medias);
|
||||
}
|
||||
|
||||
protected function storeDeferred(Request $request)
|
||||
|
@ -100,7 +98,7 @@ class MediaController
|
|||
});
|
||||
|
||||
$this->authorize('storeMedia', [$modelName, null, $collection->name]);
|
||||
return $isSingle ? DeferredMediaData::fromPath($tempPaths->first(), $collection) : response(DeferredMediaData::collectionFromPaths($tempPaths, $collection), 201);
|
||||
return $isSingle ? DeferredMediaData::fromPath($tempPaths->first(), $collection) : DeferredMediaData::collectionFromPaths($tempPaths, $collection);
|
||||
}
|
||||
|
||||
public function update(Request $request, Media $media): MediaData
|
||||
|
@ -118,7 +116,7 @@ class MediaController
|
|||
return MediaData::from($media);
|
||||
}
|
||||
|
||||
public function index(Request $request, $parentModel, int $parentId, string $collectionName): MediaData|JsonResponse
|
||||
public function index(Request $request, $parentModel, int $parentId, string $collectionName): MediaData|DataCollection
|
||||
{
|
||||
$model = app('media-library-helpers')->get($parentModel);
|
||||
$model = $model::find($parentId);
|
||||
|
@ -134,7 +132,7 @@ class MediaController
|
|||
|
||||
return $isSingle
|
||||
? MediaData::from($model->getFirstMedia($collectionName))
|
||||
: response()->json(MediaData::collect($model->getMedia($collectionName))->toArray());
|
||||
: MediaData::collection($model->getMedia($collectionName));
|
||||
}
|
||||
|
||||
public function destroy(Media $media, Request $request): JsonResponse
|
||||
|
|
|
@ -16,7 +16,7 @@ class OrderController
|
|||
$mediaCount = collect($request->order)->map(function ($media) {
|
||||
$media = Media::findOrFail($media);
|
||||
|
||||
return $media->model_id . '_' . $media->model_type;
|
||||
return $media->model_id.'_'.$media->model_type;
|
||||
})->unique()->count();
|
||||
|
||||
if (1 !== $mediaCount) {
|
||||
|
@ -31,6 +31,6 @@ class OrderController
|
|||
|
||||
$model->getMediaCollection($collectionName)->runCallback('after', $model->fresh());
|
||||
|
||||
return MediaData::collect($model->getMedia($collectionName))->toArray();
|
||||
return MediaData::collection($model->getMedia($collectionName));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|||
|
||||
test('it gets all medias', function () {
|
||||
$this->auth()->registerModel();
|
||||
$this->withoutExceptionHandling();
|
||||
$post = $this->newPost();
|
||||
$firstMedia = $post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('images');
|
||||
$secondMedia = $post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('images');
|
||||
|
|
Loading…
Reference in New Issue