我在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();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句