Skip to content

Instantly share code, notes, and snippets.

@armababy
Last active February 17, 2016 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armababy/9aa25e9672d34d6aa2fe to your computer and use it in GitHub Desktop.
Save armababy/9aa25e9672d34d6aa2fe to your computer and use it in GitHub Desktop.
MediaControlller for thumbs
<?php namespace Modules\<module_name>\Http\Controllers\Api;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Routing\Controller;
use Modules\Media\Repositories\FileRepository;
use Modules\Media\Image\Imagy;
class MediaController extends Controller
{
private $file;
private $imagy;
public function __construct(FileRepository $file, Imagy $imagy)
{
$this->file = $file;
$this->imagy = $imagy;
}
public function file(Request $request)
{
$mediaId = $request->get('mediaId');
$thumbName = $request->get('thumbName', 'mediumThumb');
if($mediaId) {
$this->file = $this->file->find($mediaId);
$this->file->thumbnail_path = $this->getThumb($thumbName);
return Response::json([
'error' => false,
'message' => 'File retrieved',
'result' => $this->file->getAttributes()
]);
}
return Response::json([
'error' => true,
'message' => 'FileId is required'
]);
}
public function getThumb($thumbName) {
return $this->imagy->getThumbnail($this->file->path, $thumbName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment