Rubenwouters\CrmLauncher\Models\Reaction::insertReaction PHP Метод

insertReaction() публичный Метод

Insert reaction in DB (eiter from a Facebook post or Tweet)
public insertReaction ( string $type, object $mention, integer $id, string $answer = null ) : Reaction
$type string
$mention object
$id integer
$answer string
Результат Reaction
    public function insertReaction($type, $mention, $id, $answer = null)
    {
        $reaction = new Reaction();
        $reaction->publishment_id = $id;
        if ($answer != null) {
            $reaction->user_id = Auth::user()->id;
        }
        if ($type == 'twitter') {
            if ($mention['user']['id_str'] != Configuration::twitterId()) {
                $reaction->user_id = $mention['user']['id_str'];
            }
            $reaction->screen_name = $mention['user']['screen_name'];
            $reaction->tweet_id = $mention['id_str'];
            $reaction->tweet_reply_id = $mention['in_reply_to_status_id_str'];
            $reaction->message = $mention['text'];
            $reaction->post_date = changeDateFormat($mention['created_at']);
        } else {
            $reaction->fb_post_id = $mention->id;
            if ($answer == null) {
                $reaction->screen_name = $mention->from->name;
                $reaction->message = $mention->message;
                $reaction->post_date = changeFbDateFormat($mention->created_time);
            } else {
                $reaction->message = $answer;
                $reaction->post_date = Carbon::now();
            }
        }
        $reaction->save();
        return $reaction;
    }

Usage Example

 /**
  * Reply post (Facebook)
  *
  * @param  Request $request
  * @param  integer  $id
  *
  * @return view
  */
 public function replyPost(Request $request, $id)
 {
     $this->validate($request, ['answer' => 'required']);
     $publishment = $this->publishment->find($id);
     if ($request->input('in_reply_to') != "") {
         $replyTo = $request->input('in_reply_to');
         $reply = $this->facebookContent->answerPost($request->input('answer'), $replyTo);
         $this->insertInnerComment($id, $request, $replyTo, $reply);
     } else {
         $replyTo = $publishment->fb_post_id;
         $reply = $this->facebookContent->answerPost($request->input('answer'), $replyTo);
         $this->reaction->insertReaction(self::TYPE_FACEBOOK, $reply, $id, $request->input('answer'));
     }
     return back();
 }
All Usage Examples Of Rubenwouters\CrmLauncher\Models\Reaction::insertReaction