3

I have a route that is dependent on 2 parameters:

Route::get('{place}/{treatment}', 'ClinicController@showResults')->name('clinic.search.results');

I am wanting to show the breadcrumb of this result as:

Home -> {Place} -> {Treatment}

But preferably, "place" should not be linked to anything as I haven't set up a route to handle "place" only. It returns a 404.

I have it set up within breadcrumbs.php as:

Breadcrumbs::register('clinic.search.results', function ($breadcrumbs, $place, $treatment) {
    $breadcrumbs->parent('location', $place);
    $breadcrumbs->push($treatment, route('clinic.search.results', $place, $treatment));
});

But an exception is thrown:

Type error: Too few arguments to function DaveJamesMiller\Breadcrumbs\BreadcrumbsServiceProvider::{closure}(), 1 passed in /home/vagrant/compare/vendor/davejamesmiller/laravel-breadcrumbs/src/BreadcrumbsGenerator.php on line 68 and exactly 3 expected (View: /home/vagrant/resources/views/clinic/search/results.blade.php)

What am I missing please? Thank you in advance.

1 Answers1

0

I think the problem should be that {Place} -> {Treatment} are another level and maybe you should check route() helper

First you should define {Place} - set to parent and push, next define {Treatment} set parent {Place} and push {Treatment}

Please check your route() helper, first param is the route name as string, second are paremeters as array. So route('clinic.search.results', ['place' => $place, 'treatment' => $treatment])

Please check bradcrumbs package documentation

and in L5.5 the route helper defined like this

if (! function_exists('route')) {
    /**
     * Generate the URL to a named route.
     *
     * @param  string  $name
     * @param  array   $parameters
     * @param  bool    $absolute
     * @return string
     */
    function route($name, $parameters = [], $absolute = true)
    {
        return app('url')->route($name, $parameters, $absolute);
    }
}
jeugen
  • 344
  • 4
  • 23