FlyAbove Posted December 25, 2022 Share Posted December 25, 2022 (edited) I am trying to find a way to delete my category that I have created. I get the error attempt to read image is null, I think the error has to do with category_id being null. How can I retrieve it for my category object? class Index extends Component { use WithPagination; protected $paginationTheme = 'bootstrap'; public $category_id; //setting category_id public function deleteCategory($category_id) { $this->category_id = $category_id; } public function destroyCategory() { $category = Category::find($this->category_id); // dd($this); $path = 'uploads/category/'.$category->image; if (File::exists($path)) { File::delete($path); } $category->delete(); session()->flash('message', 'Category Deleted'); $this->dispatchBrowserEvent('close-modal'); } public function render() { $categories = Category::orderBy('id', 'DESC')->paginate(10); return view('livewire.admin.category.index', ['categories' => $categories]); } } Edited December 25, 2022 by FlyAbove Make title more specific. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.