Jump to content

Laravel: Category Delete Not Working


FlyAbove

Recommended Posts

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 by FlyAbove
Make title more specific.
Link to comment
Share on other sites

  • FlyAbove changed the title to Laravel: Category Delete Not Working
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.