我的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工作正常,但在其他方面它不起作用。
答案 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();