Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument 2 passed to App\Providers\BreadcrumbsServiceProvider #20

Open
fbc opened this issue Oct 28, 2020 · 6 comments
Open

Argument 2 passed to App\Providers\BreadcrumbsServiceProvider #20

fbc opened this issue Oct 28, 2020 · 6 comments

Comments

@fbc
Copy link

fbc commented Oct 28, 2020

I'm getting this error:

Argument 2 passed to App\Providers\BreadcrumbsServiceProvider::App\Providers{closure}() must be an instance of App\Models\project\Project, string given (View: /var/www/resources/views/navigation/breadcrumbs.blade.php)

In app/Providers/BreadcrumbsServiceProvider.php

<?php

namespace App\Providers;

use Tabuna\Breadcrumbs\Trail;
use App\Models\project\Project;
use Tabuna\Breadcrumbs\Breadcrumbs;
use Illuminate\Support\ServiceProvider;

class BreadcrumbsServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Breadcrumbs::for('home', fn (Trail $trail) =>
        $trail->push('Dashboard', route('home')));

        Breadcrumbs::for('project.index', fn (Trail $trail) =>
        $trail->parent('home', route('home'))
            ->push('Projects', route('project.index')));

        Breadcrumbs::for('project.show', fn (Trail $trail, Project $project) =>
        $trail->parent('project.index', route('project.index'))
            ->push('View Project', route('project.show', compact('project'))));

        Breadcrumbs::for('project.bill.index', fn (Trail $trail, Project $project) =>
        $trail->parent('project.show', route('project.show', compact('project')))
            ->push('View Bills', route('project.bill.index', compact('project'))));
    }
}

in resources/views/navigation/breadcrumbs.blade.php

<div class="col-md-12">
    <div class="row">
        @if(Breadcrumbs::has())
        @foreach (Breadcrumbs::current() as $crumbs)
        @if ($crumbs->url() && !$loop->last)
        <li class="breadcrumb-item" style="list-style-type: none;">
            <a href="{{ $crumbs->url() }}">
                {{ $crumbs->title() }}
            </a>
        </li>
        @else
        <li class="breadcrumb-item active" style="list-style-type: none;">
            {{ $crumbs->title() }}
        </li>
        @endif
        @endforeach
        @endif
    </div>
</div>

I can't seem to figure out what I'm doing wrong. It works fine until I visit project.bill.index

My routes are defined as:

...
Route::resource('project', 'project\ProjectController'); // Project Crud
...
...
Route::resource('project.bill', 'project\bill\BillController'); // Bill Crud
...
@tabuna
Copy link
Owner

tabuna commented Oct 29, 2020

Hey, @fbc, I have not been able to reproduce the problem. My route opens perfectly: project.bill.index.
Is there any other data that could influence? I used laravel 8 and package with the latest version

@fbc
Copy link
Author

fbc commented Oct 29, 2020

@tabuna I'm using Laravel 7 and ver 1.3.1 of your package.

@octoquad
Copy link

@fbc I'm not sure if you figured this out yet, but see #10 (comment). In your case, the BillController::index method should look like:

public function index(Project $project) { ... }

to avoid the error you are getting.

I'm also running the same version as you.

@ahmed-magdy-hassan
Copy link

ahmed-magdy-hassan commented Dec 9, 2020

@fbc
Did you try in parent function put the name and the object without route as the second argument

Breadcrumbs::for('booths.banners.create', fn (Trail $trail, Booth $booth) =>
$trail
    ->parent('booths.banners.index', $booth)
    ->push('Create Booth Banner', route('booths.banners.create', $booth->id)));

@misha1
Copy link

misha1 commented Dec 25, 2020

help me pls( im newbee

my controller

image

when i not use breadcums all worked
Route::get('/plastinky/all/{id}', [\App\Http\Controllers\PlastinkyController::class, 'ShowOne'])
->name('plastinky-one');
image

when i use
Route::get('/plastinky/all/{id}', [\App\Http\Controllers\PlastinkyController::class, 'ShowOne'])
->name('plastinky-one')
->breadcrumbs(fn (Trail $trail) => $trail->parent('plastinky')->parent('plastinky-data')->push('VIEW', route('plastinky-one'))
);

then i have this error, how i can fix it?
image

@tabuna
Copy link
Owner

tabuna commented Dec 25, 2020

Hey @misha1. Your mistake is not the same as that of the topic author.
Your route has a required id parameter that you forgot to pass to the breadcrumb.

use App\Http\Controllers\PlastinkyController;

Route::get('/plastinky/all/{id}', [PlastinkyController::class, 'ShowOne'])
  ->name('plastinky-one')
  ->breadcrumbs(
    fn(Trail $trail, $id) => $trail->parent('plastinky')
      ->parent('plastinky-data')
      ->push('VIEW', route('plastinky-one', $id))
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants