Adding endpoint to find a file by its zone, entity and entity id

parent ba8dbaae
......@@ -68,6 +68,23 @@ class MediaController extends Controller
return new MediaTransformer($file);
}
public function findFirstByZoneEntity(Request $request)
{
$imageable = DB::table('media__imageables')
->where('imageable_id', $request->get('entity_id'))
->whereZone($request->get('zone'))
->whereImageableType($request->get('entity'))
->first();
if ($imageable === null) {
return response()->json(null);
}
$file = $this->file->find($imageable->file_id);
return new MediaTransformer($file);
}
/**
* Store a newly created resource in storage.
*
......
......@@ -31,6 +31,10 @@ $router->group(['middleware' => 'api.token'], function (Router $router) {
'uses' => 'MediaController@sortMedia',
'as' => 'api.media.sort',
]);
$router->get('media/find-first-by-zone-and-entity', [
'uses' => 'MediaController@findFirstByZoneEntity',
'as' => 'api.media.find-first-by-zone-and-entity',
]);
$router->get('media/{media}', [
'uses' => 'MediaController@find',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment