这是我的控制器的索引方法。当我运行代码时,它什么都不做。
public function index()
{
Customer::destroy(1);
return view('customer');
}
型号:
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model {
protected $guarded = [];
public $timestamps=false;
}
答案 0 :(得分:2)
尝试使用delete
代替destroy
,如下所示:
Customer::findOrFail(1)->delete();
或者您可以使用eloquent查询构建器直接从数据库中尝试:
Customer::where('id', 1)->delete();
答案 1 :(得分:0)
您也可以像这样编写代码
public function getDeleteTag($id)
{
DB::table('tags')
->where('id','=',$id)
->delete();
return Response::json(['message' => 'Tag has been deleted successfully!']);
}