atayahmet / laravel-nestable

Laravel 5 nested category/menu generator
MIT License
214 stars 52 forks source link

Call to a member function delete() on null in NestableTrait #8

Closed Sarav-S closed 7 years ago

Sarav-S commented 8 years ago

When I try deleting a record, it is throwing me this error

FatalErrorException in NestableTrait.php line 277:
Call to a member function delete() on null

My Model File

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Nestable\NestableTrait;

class Menu extends Model
{
use NestableTrait;

protected $parent = 'parent_id';

protected $fillable = ['parent_id', 'menu_id', 'name', 'slug', 'status'];
}
atayahmet commented 8 years ago

Hi @Sarav-S

It worked well in my test as follows.

Category::where('id', 1)->delete();
$category = new Category;

$category->newInstance()->where('id', 2)->delete();

Is there any example code?

Sarav-S commented 8 years ago

Hi @atayahmet

Category::where('id', 1)->delete();// this works.

But I have trying to delete by following code

$category = Category::find($id); 
// Perform some logic and then
$category->delete()
atayahmet commented 7 years ago

Hi @Sarav-S

i fixed it. Please update package.

Sarav-S commented 7 years ago

@atayahmet Great! Will update the package now. 👍