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); }
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]]); }
/** * 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'); }
/** @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); }
/** * 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]]); }
/** * 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'); }
/** * 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]]); }
/** * 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'); }