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 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题