语法错误,在Laravel
问题描述:
意外“$ POST_ID”(T_VARIABLE)我有一个问题,我在laravel语法错误,在Laravel
我试图执行下面的代码功能:
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();
}
}
但我发现了出现以下错误:syntax error, unexpected '$post_id' (T_VARIABLE)
这个函数有什么问题?如果$ post_id工作正常,但在其他方面不起作用。
答
由于@andrewsi说你在'='
之后缺少逗号。您也可以只使用此代码,这将做同样的工作:
Like::where('user_id', $user_id)->where('post_id', $post_id)->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();
或 Like::where('user_id', '=', $user_id)->where('post_id', $post_id)->get()->first()->delete();
缺少逗号在''='$ post_id'之间 – andrewsi