jordibenck
jordibenck

Reputation: 185

Laravel class 'navigation' not found

I tried to build the navigation tree from the database but I keep getting class not found error. The database table is created as well

class Navigation extends Model
{
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'navigation';

    public function parent()
    {
        return $this->hasOne('navigation', 'id', 'parent_id');
    }

    public function children()
    {
        return $this->hasMany('navigation', 'parent_id', 'id');

    }

    public static function tree()
    {
        return static::with(implode('.', array_fill(0, 4, 'children')))->where('parent_id', '=', NULL)->get();
    }
}

Upvotes: 1

Views: 314

Answers (1)

tprj29
tprj29

Reputation: 234

Assuming you have the default Laravel structure change 'navigation' to 'App/Navigation'

class Navigation extends Model
{
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'navigation';

    public function parent()
    {
        return $this->hasOne('App/Navigation', 'id', 'parent_id');
    }

    public function children()
    {
        return $this->hasMany('App/Navigation', 'parent_id', 'id');

    }

Upvotes: 3

Related Questions