doucao1888 2016-09-21 02:19
浏览 87
已采纳

语法错误,Laravel中的意外'$ post_id'(T_VARIABLE)[重复]

This question already has an answer here:

I have a problem with my function in laravel

I am trying to execute the following code:

public static function likePost($value)
{
   $post_id = $value['post_id']; 
   $user_id = $value['user_id']; 
   if($value['liked'] == "1")
   {
      $model = new Like;
      $model->fill($value);
      $model->created = time();
      if($model->save())
      {
        $post = Post::with('user')->where('id', '=', $value['post_id'])->get()->first();
        $text = $post['user']['name']." ".Notification::TEXT_LIKE_POST;
        Push::push($text, $value['post_id']);
      }
   }
   else
   {
      Like::where('user_id', '=', $user_id)->where('post_id', '=' $post_id)->get()->first()->delete();
   }
}

But I'm getting the following error: syntax error, unexpected '$post_id' (T_VARIABLE)

What is wrong with this function? Inside of the if the $post_id work fine, but in the else it don't work.

</div>
  • 写回答

2条回答 默认 最新

  • dongyue3795 2016-09-21 02:41
    关注

    As @andrewsi said you have missing comma after '='. Also you can just use this code which will do the same job:

    Like::where('user_id', $user_id)->where('post_id', $post_id)->delete();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化