public function delete($id) { $cate = Danhmucsanpham::find($id); DB::beginTransaction(); try { if ($cate->parent != 0) { // $cate->tintucs()->detach(); Danhmucsanpham::destroy($id); } else { $cate_child = Danhmucsanpham::where('parent', '=', $id)->get(); foreach ($cate_child as $key => $value) { $value->parent = 0; $value->save(); // print_r($value->id); } // die(); // $cate->tintucs()->detach(); Category::destroy($id); } } catch (\Exception $e) { DB::rollBack(); return false; } DB::commit(); return true; }
/** * delete a category with given id. * * @param integer $id * @return boolean */ public function delete($id) { if ($id) { $this->model->destroy($id); DB::table('categorizables')->where('category_id', $id)->delete(); Cache::forget('home.content'); return true; } }
public function Test_of_beforeDestroy() { $CategoryA = new DependentCategory(); $CategoryA->description = "Cat A"; $CategoryB = new Category(); $CategoryB->description = "Cat B"; $CategoryAa = new DependentCategory(); $CategoryAa->description = "Cat Aa"; $CategoryBa = new Category(); $CategoryBa->description = "Cat Ba"; $CategoryA->tree->addChild($CategoryAa); $CategoryB->tree->addChild($CategoryBa); $CategoryA->destroy(); $this->assertFalse($CategoryAa->reload()); $CategoryB->destroy(); $this->assertTrue($CategoryBa->reload()); $this->assertFalse($CategoryBa->tree->hasParent()); }
/** * Remove the specified category from storage. * * @param int $id * @return Response */ public function destroy($id) { Category::destroy($id); return Redirect::route('categories.index'); }
/** * Remove the specified category from storage. * * @param int $id * @return Response */ public function destroy($id) { Category::destroy($id); return Redirect::route('admin.categories.index')->withErrors('Item had deleted!'); }
/** * Remove the specified category from storage. * * @param int $id * @return Response */ public function destroy($id) { if (Category::destroy($id)) { //Show message $alert[] = ['class' => 'alert-success', 'message' => '<strong><i class="fa fa-check"></i></strong> Excluído!']; Session::flash('alerts', $alert); } return Redirect::to(URL::previous()); }
public function categories_delete() { $this->load->library('form_validation'); if ($this->form_validation->run('delete-category') == FALSE) { redirect($this->session->previous_url, 'refresh'); } else { $category = Category::find($this->input->post('id')); Category::destroy($this->input->post('id')); $this->session->set_flashdata('message', 'Successfully deleted <strong>' . $category->name . '</strong>'); redirect('dashboard/categories', 'refresh'); } }