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]]);
 }
Example #2
0
 /**
  * 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]]);
 }
Example #3
0
 public function unlink(Module $module, Request $request, FileRepository $fileRepository, Imagy $imagy)
 {
     DB::table('media__imageables')->whereFileId($request->get('fileId'))->delete();
     $file = $fileRepository->find($request->get('fileId'));
     $imagy->deleteAllFor($file);
     $fileRepository->destroy($file);
 }
Example #4
0
 /**
  * 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]]);
 }
Example #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  Module $module
  * @return Response
  */
 public function destroy(Module $module, FileRepository $fileRepository, Imagy $imagy)
 {
     if ($module->images->count() > 0) {
         foreach ($module->images as $image) {
             \DB::table('media__imageables')->whereFileId($image->id)->delete();
             $file = $fileRepository->find($image->id);
             $imagy->deleteAllFor($file);
             $fileRepository->destroy($file);
         }
     }
     $this->module->destroy($module);
     flash()->success(trans('core::core.messages.resource deleted', ['name' => trans('module::modules.title.modules')]));
     return redirect()->route('admin.module.module.index');
 }