Breadcrumb with Laravel API

Posted 1 month ago by mhdmirzaie

Hi everyone,

I have created a recursive category for my document management system. I have created Model, Controller and it works properly. Now I want to add a Breadcrumb which shows address of current folder with its parents. I dont know how to make this dynamic Breadcrumb. my application has been created Laravel at backend and Angular in frontend. it would be appericiated if help me how to make the dynamic Breadcrumb.

Best,

Mir

// Model

class Category extends Model{

public function documents(){
    return $this->hasMany(Document::class);
}
public function children(){
    return $this->hasMany(Category::class, 'parent_id')->with('children');
}
public function parent(){
    return $this->belongsTo(Category::class, 'parent_id');
}

}

//Controller

public function index($category=0){

    $categories = Category::whereParentId($category)->with('documents', 'children')->paginate(24);
    return CategoryResource::collection($categories);
}

Please sign in or create an account to participate in this conversation.