コード例 #1
0
 /**
  * @param array $data
  * @return \HorseStories\Models\Statuses\Status
  */
 public function create($data = [])
 {
     $status = new Status();
     $status->body = $data['status'];
     $status->horse_id = $data['horse'];
     $status->save();
     if (array_key_exists('picture', $data)) {
         $horse = $this->horses->findById($data['horse']);
         $picture = $this->uploader->uploadPicture($data['picture'], $horse);
         $status->setPicture($picture);
     }
     return $status;
 }
コード例 #2
0
 /**
  * @param int $status
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store($status)
 {
     $status = Status::findOrFail($status);
     $comment = $this->commentCreator->create($status, Input::get('body'));
     $data = ['sender' => Auth::user()->username, 'horse' => $status->horse->name];
     event(new CommentWasPosted($comment->status, Auth::user(), Notification::COMMENT_POSTED, $data));
     Session::put('success', 'Your comment was posted');
     return response()->json('success', 200);
 }
コード例 #3
0
 /**
  * @param int $status
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function like($status)
 {
     $status = Status::findOrFail($status);
     $likes = DB::table('likes')->whereUserId(Auth::user()->id)->lists('status_id');
     if (in_array($status->id, $likes)) {
         Auth::user()->likes()->detach($status);
     } else {
         Auth::user()->likes()->attach($status);
         $data = ['sender' => Auth::user()->username, 'horse' => $status->horse->name];
         event(new StatusLiked($status, Auth::user(), Notification::STATUS_LIKED, $data));
     }
     return response()->json('success', 200);
 }
コード例 #4
0
 /**
  * @param \HorseStories\Models\Horses\Horse $horse
  * @return \HorseStories\Models\Statuses\Status[]
  */
 public function getFeedForHorse(Horse $horse)
 {
     return $this->status->where('horse_id', $horse->id)->orderBy('created_at', 'DESC')->get();
 }