Last active
February 23, 2016 14:14
-
-
Save armababy/10e3a5457bcd167e2d2b to your computer and use it in GitHub Desktop.
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 | |
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