public static function upload($filePath, $user, $topic = null)
{
$cover = new static();
DB::transaction(function () use($cover, $filePath, $user, $topic) {
$cover->save();
// get id
$cover->user()->associate($user);
$cover->topic()->associate($topic);
$cover->storeFile($filePath);
$cover->save();
});
return $cover;
}
public function store() { if (Request::hasFile('cover_file') !== true) { abort(422); } $topic = null; if (presence(Request::input('topic_id')) !== null) { $topic = Topic::findOrFail(Request::input('topic_id')); priv_check('ForumTopicEdit', $topic)->ensureCan(); if ($topic->cover !== null) { abort(422); } } try { $cover = TopicCover::upload(Request::file('cover_file')->getRealPath(), Auth::user(), $topic); } catch (ImageProcessorException $e) { return error_popup($e->getMessage()); } return json_item($cover, new TopicCoverTransformer()); }