Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 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]]);
 }
Exemplo n.º 3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->line('Preparing to regenerate all thumbnails...');
     foreach ($this->file->all() as $file) {
         $this->imagy->createAll($file->path);
     }
     $this->info('All thumbnails refreshed');
 }
Exemplo n.º 4
0
 /** @test */
 public function it_should_detect_an_image()
 {
     $jpg = $this->imagy->isImage('image.jpg');
     $png = $this->imagy->isImage('image.png');
     $pdf = $this->imagy->isImage('pdf.pdf');
     $this->assertTrue($jpg);
     $this->assertTrue($png);
     $this->assertFalse($pdf);
 }
Exemplo n.º 5
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]]);
 }
Exemplo n.º 6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  File     $file
  * @internal param int $id
  * @return Response
  */
 public function destroy(File $file)
 {
     $this->imagy->deleteAllFor($file);
     $this->file->destroy($file);
     flash(trans('media::messages.file deleted'));
     return redirect()->route('admin.media.media.index');
 }
Exemplo n.º 7
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]]);
 }
Exemplo n.º 8
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');
 }