Skip to content

Instantly share code, notes, and snippets.

@armababy
Last active February 23, 2016 14:14
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/10e3a5457bcd167e2d2b to your computer and use it in GitHub Desktop.
Save armababy/10e3a5457bcd167e2d2b to your computer and use it in GitHub Desktop.
<?php
use Modules\Media\Http\Controllers\Api\MediaController;
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @param Route $route
* @param MediaController $media
* @return Response
*/
public function store(StoreGameRequest $request, MediaController $media)
{
$this->game = $this->game->create($request->all());
if($this->game->id) {
// Get mediaId and zone from request
$mediaId = $request->get('mediaId');
$mediaZone = $request->get('mediaZone');
if($mediaId && $mediaZone) {
// Link media file with entity
$mediaData = [
'mediaId' => $mediaId,
'_token' => csrf_token(),
'entityClass' => (new \ReflectionClass($this->game))->getName(), // You can also hardcode entity here if you like
'entityId' => $this->game->id,
'zone' => $mediaZone
];
$req = Request::createFromBase(Request::create('', 'POST', $mediaData));
$res = $media->linkMedia($req);
}
flash()->success(trans('core::core.messages.resource created', ['name' => trans('<module_name>::games.title.games')]));
}
return redirect()->route('admin.<module_name>.<entity_name>.index');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment