函数删除不适用于mysql

时间:2018-03-15 10:33:12

标签: laravel controller

干草..我的控制器上有功能删除..在客户端,当我删除catagories是工作..但是,当我检查哦phpmyadmin。类别仍未删除.. 这是我的categoriesController for delete ..

 .........




    public function destroy(Request $request,$id)
        {
            try {
                DB::beginTransaction();

                $category = Category::find($id);
                $category->delete();

                $request->session()->flash('alert-success','Data successfully deleted');

                DB::commit(); 

                return redirect(route('categories.index'));
            }
            catch (Exception $e) {
                return Redirect::back()->with('error_message', $e->getMessage())->withInput();
            }  
        }

请帮助..谢谢

2 个答案:

答案 0 :(得分:0)

您应该尝试使用以下代码:

//For delete category

DB::table('category')->where('id',$id)->delete();

$category = Category::find($id);    
$category->forceDelete();

答案 1 :(得分:0)

尝试这样做:

public function destroy($id) 
{
    $category = Category::destroy($id);
}