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

时间:2016-09-21 02:19:29

标签: php laravel

我的laravel功能有问题

我正在尝试执行以下代码:

min

但是我收到以下错误: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(); } }

这个功能有什么问题?如果$ post_id工作正常,但在其他方面它不起作用。

2 个答案:

答案 0 :(得分:1)

因为@andrewsi说你在'='之后丢失了逗号。您也可以使用此代码执行相同的工作:

Like::where('user_id', $user_id)->where('post_id', $post_id)->delete();

答案 1 :(得分:0)

你错过了, Like::where('user_id', '=', $user_id)->where('post_id', '=' $post_id)->get()->first()->delete();

它应该是 Like::where('user_id', '=', $user_id)->where('post_id', '=', $post_id)->get()->first()->delete();

Like::where('user_id', '=', $user_id)->where('post_id', $post_id)->get()->first()->delete();