如何删除 Laravel 5.2 中的重复行
How to delete duplicated row in Laravel 5.2
我尝试删除代码中的重复行:
$post = new posts();
$post->raw('DELETE b1 FROM baroot b1,baroot b2 WHERE b1.post_id = b2.post_id AND b1.id > b2.id');
我的型号代码是:
class posts extends Model
{
protected $table = 'baroot';
protected $fillable = [
'post_id', 'title', 'modify',
];
}
我尝试删除与 :
重复的内容
$post = new posts();
$post->raw('DELETE b1 FROM posts b1,posts b2 WHERE b1.post_id = b2.post_id AND b1.id > b2.id');
但没有删除任何重复的行,我知道 sql 查询是正确的,但不适用于我的 laravel 代码
来自“Running Raw SQL Queries”的文档
Running A Delete Statement
The delete method should be used to delete records from the database.
Like update, the number of rows deleted will be returned:
$deleted = DB::delete('delete from users');
所以你必须执行
$deleted = DB::delete('DELETE b1 FROM baroot b1,baroot b2 WHERE b1.post_id = b2.post_id AND b1.id > b2.id');
我尝试删除代码中的重复行:
$post = new posts();
$post->raw('DELETE b1 FROM baroot b1,baroot b2 WHERE b1.post_id = b2.post_id AND b1.id > b2.id');
我的型号代码是:
class posts extends Model
{
protected $table = 'baroot';
protected $fillable = [
'post_id', 'title', 'modify',
];
}
我尝试删除与 :
重复的内容$post = new posts();
$post->raw('DELETE b1 FROM posts b1,posts b2 WHERE b1.post_id = b2.post_id AND b1.id > b2.id');
但没有删除任何重复的行,我知道 sql 查询是正确的,但不适用于我的 laravel 代码
来自“Running Raw SQL Queries”的文档
Running A Delete Statement
The delete method should be used to delete records from the database. Like update, the number of rows deleted will be returned:
$deleted = DB::delete('delete from users');
所以你必须执行
$deleted = DB::delete('DELETE b1 FROM baroot b1,baroot b2 WHERE b1.post_id = b2.post_id AND b1.id > b2.id');