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条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集