diglactic / laravel-breadcrumbs

Laravel Breadcrumbs - A simple Laravel-style way to create breadcrumbs.
https://packagist.org/packages/diglactic/laravel-breadcrumbs
MIT License
868 stars 63 forks source link

Diglactic\Breadcrumbs\ServiceProvider::{closure}(): Argument #2 ($page) must be of type App\Models\Pages, int given #74

Closed Britaniik closed 1 year ago

Britaniik commented 1 year ago

Hi please help me i am facing with eror.I did all as documentation

// routes/breadcrumbs.php file like this:

Breadcrumbs::for('pages', function (BreadcrumbTrail $trail,  App\Models\Pages $page) {

    if(is_null($page->parent_id))
    {

        $trail->parent('home');
    }
    else
    {
        $trail->parent('pages', $page->parent_id);
    }

    switch (LaravelLocalization::getCurrentLocale())
    {
        case "uz":  $trail->push($page->title_uz,route('page.show',['data'=> $page->slug]));
            break;
        case "ru":  $trail->push($page->title_ru,route('page.show',['data'=> $page->slug]));
            break;
        case "en":  $trail->push($page->title_en,route('page.show',['data'=> $page->slug]));
            break;
    }

});

In view file i call it like this: {{ Breadcrumbs::render('pages', $page) }}

In result i get this error

Diglactic\Breadcrumbs\ServiceProvider::{closure}(): Argument https://github.com/dwightwatson/breadcrumbs/issues/2 ($page) must be of type App\Models\Pages, int given, called in C:\OSPanel\domains\laravel.loc\vendor\diglactic\laravel-breadcrumbs\src\Generator.php on line 64

shengslogar commented 1 year ago

Based on the code you've pasted, $trail->parent('pages', $page->parent_id); should be $trail->parent('pages', $page);. That is why you're receiving the error must be of type App\Models\Pages, int given.