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

Returning a view with multiple parameters #58

Closed cesarMtorres closed 1 year ago

cesarMtorres commented 1 year ago

hi there,

I have a problem when using compact with multiple parameters to return

// web/ breadcrumbs.php


// Provider > [Games id]  > Attributes  
Breadcrumbs::for('games.attributes', function (BreadcrumbTrail $trail, Game $game) {

    $trail->parent(__('providers.games'), $game->provider_id);

    $trail->push($game->name , route('games.attributes', $game));
});
```php

// Controler

  ```php

  public function attributes(Game $game)
    {
        $attributes = $this->gamesAttributes->getAttributesByGame($game);

        return view('admin.providers.games.attributes.index', compact('attributes','game')); // 2 parameters to return 
    } 
```php

but not work  because  compact( "attributes")  is empty in view  

The only way this work is

```php

Breadcrumbs::for('games.attributes', function (BreadcrumbTrail $trail, $game) {

    $game = Game::findOrFail($game);   // HERE WORK

    $trail->parent(__('providers.games'), $game->provider_id);

    $trail->push($game->name, route('games.attributes', $game));
});

```php

And compact("attribute") in the controller work correctly in the view
shengslogar commented 1 year ago

It's unclear how the code you posted is causing the error you're getting. You'll need to either break this out into a standalone repository or provide more context.

The error you posted ("attributes is empty in view") would not be coming from this package, but from Laravel itself. You'll have better luck asking this question over on a Laravel-focused forum.

This package and the way views connect to Laravel controllers are entirely separate.