upload() public static method

public static upload ( $filePath, $user, $topic = null )
Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
 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'));
         $this->authorizePost($topic->forum, $topic);
         if ($topic->canBeEditedBy(Auth::user()) !== true) {
             abort(403);
         }
         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 fractal_item_array($cover, new TopicCoverTransformer());
 }
Ejemplo n.º 3
0
 public function setCover($path, $user)
 {
     if ($this->cover === null) {
         TopicCover::upload($path, $user, $this);
     } else {
         $this->cover->storeFile($path);
         $this->cover->user()->associate($user);
         $this->cover->save();
     }
     return $this->fresh();
 }