App\Http\Controllers\Forum\TopicCoversController::store PHP Method

store() public method

public store ( )
    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());
    }