public function linkMedia(Request $request) { $mediaId = $request->get('mediaId'); $file = $this->file->find($mediaId); $path = $file->path->getUrl(); $thumbnailPath = $this->imagy->getThumbnail($file->path, 'mediumThumb'); return Response::json(['error' => false, 'message' => 'The link has been added.', 'result' => ['path' => $path, 'thumb' => $thumbnailPath]]); }
/** * Link the given entity with a media file * @param Request $request */ public function linkMedia(Request $request) { $mediaId = $request->get('mediaId'); $entityClass = $request->get('entityClass'); $entityId = $request->get('entityId'); $entity = $entityClass::find($entityId); $zone = $request->get('zone'); $entity->files()->attach($mediaId, ['imageable_type' => $entityClass, 'zone' => $zone]); $imageable = DB::table('media__imageables')->whereFileId($mediaId)->whereZone($zone)->whereImageableType($entityClass)->first(); $file = $this->file->find($imageable->file_id); $thumbnailPath = $this->imagy->getThumbnail($file->path, 'mediumThumb'); event(new FileWasLinked($file, $entity)); return Response::json(['error' => false, 'message' => 'The link has been added.', 'result' => ['path' => $thumbnailPath, 'imageableId' => $imageable->id]]); }
/** * Link the given entity with a media file * * @param Request $request */ public function linkMedia(Request $request) { $mediaId = $request->get('mediaId'); $entityClass = $request->get('entityClass'); $entityId = $request->get('entityId'); $order = $request->get('order'); $entity = $entityClass::find($entityId); $zone = $request->get('zone'); $entity->files()->attach($mediaId, ['imageable_type' => $entityClass, 'zone' => $zone, 'order' => $order]); $imageable = DB::table('media__imageables')->whereFileId($mediaId)->whereZone($zone)->whereImageableType($entityClass)->first(); $file = $this->file->find($imageable->file_id); if (str_contains($file->mimetype, 'video')) { $thumbnailPath = $file->path->getRelativeUrl(); $mediaType = 'video'; } else { $thumbnailPath = $this->imagy->getThumbnail($file->path, 'mediumThumb'); $mediaType = 'image'; } event(new FileWasLinked($file, $entity)); return Response::json(['error' => false, 'message' => 'The link has been added.', 'result' => ['path' => $thumbnailPath, 'imageableId' => $imageable->id, 'mediaType' => $mediaType]]); }
/** @test */ public function it_should_return_same_path_for_non_images() { $path = $this->imagy->getThumbnail("{$this->mediaPath}test-pdf.pdf", 'smallThumb'); $expected = "{$this->mediaPath}test-pdf.pdf"; $this->assertEquals($expected, $path); }