public static function upload($filePath, $user, $forum = null)
{
$cover = new static();
DB::transaction(function () use($cover, $filePath, $user, $forum) {
$cover->save();
// get id
$cover->user()->associate($user);
$cover->forum()->associate($forum);
$cover->storeFile($filePath);
$cover->save();
});
return $cover;
}
public function store() { if (Request::hasFile('cover_file') !== true) { abort(422); } $forum = Forum::findOrFail(Request::input('forum_id')); if ($forum->cover !== null) { abort(422); } try { $cover = ForumCover::upload(Request::file('cover_file')->getRealPath(), Auth::user(), $forum); } catch (ImageProcessorException $e) { return error_popup($e->getMessage()); } return fractal_item_array($cover, new ForumCoverTransformer()); }