我从数据库删除数据几乎没有问题。我刮一下并将数据保存到数据库中。我抓取了同一网站进行多次更新。和之前的数据抓取。该网站不再存在。然后,我也想从数据库中删除该数据的ID。
foreach($planNames as $k => $names)
{
$database = [];
$database = [
"plan_id" => $insertedPlaceId,
"plan_name" => $names,
"plan_price" => $planPrice[$k],
"people" => $people[$k]
];
if ($plan = Plan::where("plan_name", "=", $names)->first()) {
if ($plan->plan_name != $database["plan_name"]) {
$plan->id->delete();
$this->line("Plan deleted.");
}
} else {
Plan::insertGetId($database);
$this->line("Plans inserted.");
}
}
我认为这部分工作$plan->id->delete();
答案 0 :(得分:2)
/* Separate your state across multiple hooks */
const [data, setData] = useState({});
const [product, setProduct] = useState('profile');
useEffect(() => {
getProducts(1).then(res =>
/* Only update data portion of state via setData hook */
setData(res.data)
);
}, []);
不是正确的方法,可以使用以下方法之一:
要删除模型,请在模型实例上调用delete方法:
$plan->id->delete()
通过Key删除现有模型
$plan = App\Plan::find(1);
$plan->delete();
通过查询删除模型
App\Plan::destroy(1); -- Using id
App\Plan::destroy(1, 2, 3); -- Using comma separated string
App\Plan::destroy([1, 2, 3]); -- Using array
如果您正在使用SoftDelete,请参阅Laravel - Soft Delete