Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.