Last active
February 17, 2016 16:36
-
-
Save armababy/9aa25e9672d34d6aa2fe to your computer and use it in GitHub Desktop.
MediaControlller for thumbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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