mercredi 6 mai 2020

Displaying breadcrumbs in laravel

I am beginner in Laravel and PHP. I use this component: https://github.com/lazychaser/laravel-nestedset in my Laravel 6 project.

I have migration:

Schema::create('categories', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('category_name', 155);
            $table->string('description', 155)->nullable();
            $table->string('keywords', 155)->nullable();
            $table->longText('content')->nullable();
            $table->char('enable', 1)->default(0);
            $table->string('photo', 155)->nullable();
            $table->bigInteger('order')->default(0);
            $table->string('slug', 160)->nullable();
            NestedSet::columns($table);
            $table->engine = "InnoDB";
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
        });

And my controller:

public function index(Request $request)
    {
        return view('category_list', ['categories' => $this->model->getCachedAllCategory()]);
    }

Repository:

public function getCachedAllCategory()
    {
        return Cache::remember('category', 43200, function () {
            return $this->model->where('parent_id', null)->orderBy('order', 'ASC')->get()->toTree();
        });
    }

I would like to display breadcrumbs. Let's assume that I have ID = 3 (I am on such a subpage) and I would like to display all branches / categories which are in front of my current category (they are its parent). How to do it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire