Closed schel4ok closed 8 years ago
It looks like the $item
parameter is optional in the route & controller:
Route::get('news/{item?}', ['as' => 'news', 'uses' => 'NewsController@getItem']);
public function getItem($item = null)
But required in the breadcrumbs:
Breadcrumbs::register('news', function($breadcrumbs, $item) {
Perhaps you need to make it optional there too?
Breadcrumbs::register('news', function($breadcrumbs, $item = null) {
Or personally I would split your single route into two separate actions (like in https://laravel.com/docs/5.3/controllers#resource-controllers):
Route::get('news', ['as' => 'news.index', 'uses' => 'NewsController@index']);
Route::get('news/{item}', ['as' => 'news.show', 'uses' => 'NewsController@show']);
ok. I changed according to your advice, but still not working.
app/Http/routes.php
Route::get('news', ['as' => 'news.index', 'uses' => 'NewsController@getIndex']);
Route::get('news/{item}', ['as' => 'news.item', 'uses' => 'NewsController@getItem']);
NewsController.php
public function getIndex()
{
$category = Category::where('type', '=', 'news')->first();
$news = News::orderBy('created_at', 'desc')->paginate(10); // все новости по 10 штук на страницу
return view('news.index')->withNews($news)->withCategory($category);
}
public function getItem($item)
{
$item = News::whereSef($item)->first();
$previous = News::where('id', '<', $item->id)->orderBy('id', 'desc')->first();
$next = News::where('id', '>', $item->id)->orderBy('id', 'asc')->first();
$category = Category::where('id', $item->category_id)->first();
return view('news.item')
->withCategory($category)
->withItem($item)
->withPrevious($previous)
->withNext($next);
Breadcrumbs.php
// Home > News
Breadcrumbs::register('news.index', function($breadcrumbs) {
$breadcrumbs->parent('home');
$breadcrumbs->push('Новости', route('news.index'));
});
// Home > News > Item
Breadcrumbs::register('news.item', function($breadcrumbs, $item) {
$breadcrumbs->parent('news.index');
$breadcrumbs->push($item->id, route('news.item'));
});
only Home > News is working.
Home > News > Item gives me an error like $item
is not an object
Whoops, looks like something went wrong.
3/3 ErrorException in breadcrumbs.php line 25: Trying to get property of non-object (View: D:\OpenServer\domains\steklo.dev\resources\views\layout\main.blade.php) (View: D:\OpenServer\domains\steklo.dev\resources\views\layout\main.blade.php)
in breadcrumbs.php line 25
at CompilerEngine->handleViewException(object(ErrorException), '0') in PhpEngine.php line 44
at PhpEngine->evaluatePath('D:\OpenServer\domains\steklo.dev\storage\framework\views/8214fa12704e0affa4131cbe30ff385c', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in CompilerEngine.php line 58
at CompilerEngine->get('D:\OpenServer\domains\steklo.dev\resources\views/news/item.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in View.php line 147
at View->getContents() in View.php line 118
at View->renderContents() in View.php line 83
at View->render() in Response.php line 51
at Response->setContent(object(View)) in Response.php line 202
at Response->__construct(object(View)) in Router.php line 1229
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(NewsController), object(Route), object(Request), 'getItem') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\NewsController', 'getItem') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
2/3 ErrorException in breadcrumbs.php line 25: Trying to get property of non-object (View: D:\OpenServer\domains\steklo.dev\resources\views\layout\main.blade.php)
in breadcrumbs.php line 25
at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('D:\OpenServer\domains\steklo.dev\storage\framework\views/b8265e1c9553960797f29caaf0b1dd60', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'obLevel' => '0', 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in CompilerEngine.php line 58
at CompilerEngine->get('D:\OpenServer\domains\steklo.dev\resources\views/layout/main.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'obLevel' => '0', 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in View.php line 147
at View->getContents() in View.php line 118
at View->renderContents() in View.php line 83
at View->render() in 8214fa12704e0affa4131cbe30ff385c line 50
at include('D:\OpenServer\domains\steklo.dev\storage\framework\views\8214fa12704e0affa4131cbe30ff385c') in PhpEngine.php line 42
at PhpEngine->evaluatePath('D:\OpenServer\domains\steklo.dev\storage\framework\views/8214fa12704e0affa4131cbe30ff385c', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in CompilerEngine.php line 58
at CompilerEngine->get('D:\OpenServer\domains\steklo.dev\resources\views/news/item.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in View.php line 147
at View->getContents() in View.php line 118
at View->renderContents() in View.php line 83
at View->render() in Response.php line 51
at Response->setContent(object(View)) in Response.php line 202
at Response->__construct(object(View)) in Router.php line 1229
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(NewsController), object(Route), object(Request), 'getItem') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\NewsController', 'getItem') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
1/3 ErrorException in breadcrumbs.php line 25: Trying to get property of non-object
in breadcrumbs.php line 25
at HandleExceptions->handleError('8', 'Trying to get property of non-object', 'D:\OpenServer\domains\steklo.dev\app\Http\breadcrumbs.php', '25', array('breadcrumbs' => object(Generator), 'item' => 'novye-dushevye-kabini')) in breadcrumbs.php line 25
at ServiceProvider->{closure}(object(Generator), 'novye-dushevye-kabini')
at call_user_func_array(object(Closure), array(object(Generator), 'novye-dushevye-kabini')) in Generator.php line 24
at Generator->call('news.item', array('novye-dushevye-kabini')) in Generator.php line 13
at Generator->generate(array('home' => object(Closure), 'about' => object(Closure), 'news.index' => object(Closure), 'news.item' => object(Closure), 'contacts' => object(Closure), 'sitemap' => object(Closure)), 'news.item', array('novye-dushevye-kabini')) in Manager.php line 114
at Manager->renderIfExists() in Facade.php line 213
at Facade::__callStatic('renderIfExists', array()) in b8265e1c9553960797f29caaf0b1dd60 line 47
at Facade::renderIfExists() in b8265e1c9553960797f29caaf0b1dd60 line 47
at include('D:\OpenServer\domains\steklo.dev\storage\framework\views\b8265e1c9553960797f29caaf0b1dd60') in PhpEngine.php line 42
at PhpEngine->evaluatePath('D:\OpenServer\domains\steklo.dev\storage\framework\views/b8265e1c9553960797f29caaf0b1dd60', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'obLevel' => '0', 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in CompilerEngine.php line 58
at CompilerEngine->get('D:\OpenServer\domains\steklo.dev\resources\views/layout/main.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'obLevel' => '0', 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in View.php line 147
at View->getContents() in View.php line 118
at View->renderContents() in View.php line 83
at View->render() in 8214fa12704e0affa4131cbe30ff385c line 50
at include('D:\OpenServer\domains\steklo.dev\storage\framework\views\8214fa12704e0affa4131cbe30ff385c') in PhpEngine.php line 42
at PhpEngine->evaluatePath('D:\OpenServer\domains\steklo.dev\storage\framework\views/8214fa12704e0affa4131cbe30ff385c', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in CompilerEngine.php line 58
at CompilerEngine->get('D:\OpenServer\domains\steklo.dev\resources\views/news/item.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'category' => object(Category), 'item' => object(News), 'previous' => object(News), 'next' => null)) in View.php line 147
at View->getContents() in View.php line 118
at View->renderContents() in View.php line 83
at View->render() in Response.php line 51
at Response->setContent(object(View)) in Response.php line 202
at Response->__construct(object(View)) in Router.php line 1229
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(NewsController), object(Route), object(Request), 'getItem') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\NewsController', 'getItem') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
Home > News > Item gives me an error like $item is not an object
That's because $item
is a string not an object, as you demonstrate here in the controller:
$item = News::whereSef($item)->first();
(The breadcrumbs closure receives the same parameters as the controller action.)
So you either need to add that same line into the breadcrumbs, like this: http://laravel-breadcrumbs.davejamesmiller.com/en/latest/routing.html#name-your-breadcrumbs-to-match
Or (recommended) use route model binding (whether explicit or implicit): http://laravel-breadcrumbs.davejamesmiller.com/en/latest/routing.html#route-model-binding https://www.laravel.com/docs/5.3/routing#route-model-binding
Sorry, but I cannot understand why $item = News::whereSef($item)->first();
is not an object.
Why in blade template I get $item
as an object, but in your breadcrumbs it is just a string
In blade template I am directly use $item->title
to render the title of current page and it works.
But in your breadcrumbs I need to make double copy of string from NewsController $item = News::whereSef($item)->first();
I didn't use route model binding. I can see that it is well documented for 5.3, but for 5.1 is documented very poor. Only for whom using id. Personally I am injecting sef as route parameter and I don't know how to make route binding with sef. I tried to update my Laravel to 5.3 to use all the latest features, but I experienced some strange bug, which makes composer not resolvable. And it is well known at github. So I decided to stay with 5.1 now as it is long term version.
I was referring to the inner $item
here:
$item = News::whereSef($item)->first();
// ^^^^^
Which comes from the parameter here:
public function getItem($item)
// ^^^^^
That is a string, and that's what the Breadcrumbs closure receives. The fact that you happened to use the same variable name in your view doesn't change anything.
Route model binding is really simple even in 5.1.
Route::bind('newsitem', function($item) {
return News::whereSef($item)->firstOrFail();
});
Route::get('news/{newsitem}', ['as' => 'news.item', 'uses' => 'NewsController@getItem']);
Now $item
will be an object in both the controller and breadcrumbs.
thanks for your help, but this still not working
Class 'App\Providers\News' not found
if I try to import use App\News;
in the top of RouteServiceProvider.php then I get error
Whoops, looks like something went wrong.
1/1 ReflectionException in RouteDependencyResolverTrait.php line 81: Class App\Http\Controllers\App\News does not exist
in RouteDependencyResolverTrait.php line 81
at ReflectionParameter->getClass() in RouteDependencyResolverTrait.php line 81
at ControllerDispatcher->transformDependency(object(ReflectionParameter), array('newsitem' => object(News)), array('newsitem' => object(News))) in RouteDependencyResolverTrait.php line 61
at ControllerDispatcher->resolveMethodDependencies(array('newsitem' => object(News)), object(ReflectionMethod)) in RouteDependencyResolverTrait.php line 44
at ControllerDispatcher->resolveClassMethodDependencies(array('newsitem' => object(News)), object(NewsController), 'getItem') in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(NewsController), object(Route), 'getItem') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(NewsController), object(Route), object(Request), 'getItem') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\NewsController', 'getItem') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 708
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 710
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 675
at Router->dispatchToRoute(object(Request)) in Router.php line 635
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
Did you change anything in the controller, like adding a type hint?
in controller I just did like that to see what will be inside $newsitem
public function getItem($newsitem)
{
//$item = News::whereSef($item)->first();
dd($newsitem);
}
In that case I have no idea.
Sorry I posted my controller not 100% as it was.
I found the problem. That was because in my controller I had App\News
like it was described in laravel documentation. I deleted it and now it works.
public function getItem(App\News $newsitem)
{
//$item = News::whereSef($item)->first();
dd($newsitem);
}
Summary of issue Don't understand from readme how to make breadcrumbs for dynamic pages. In this issue news breadcrumb is not working
The complete error message, including file & line numbers Whoops, looks like something went wrong. 3/3 ErrorException in breadcrumbs.php line 18: Missing argument 2 for DaveJamesMiller\Breadcrumbs\ServiceProvider::{closure}() (View: D:\OpenServer\domains\steklo.dev\resources\views\layout\main.blade.php) (View: D:\OpenServer\domains\steklo.dev\resources\views\layout\main.blade.php)
2/3 ErrorException in breadcrumbs.php line 18: Missing argument 2 for DaveJamesMiller\Breadcrumbs\ServiceProvider::{closure}() (View: D:\OpenServer\domains\steklo.dev\resources\views\layout\main.blade.php)
1/3 ErrorException in breadcrumbs.php line 18: Missing argument 2 for DaveJamesMiller\Breadcrumbs\ServiceProvider::{closure}()
Software versions Laravel Breadcrumbs: 3.0.1 Laravel: 5.1.43 "name": "laravel/framework", "version": "v5.1.43", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", "reference": "db580b5b073ea3f1e095b30a75ae5d6394eb8e51" PHP: 5.5.28
Copy of
app/Http/breadcrumbs.php
Copy of
app/Http/routes.php
Copy of the layout files
resources/views/layout/master.blade.php
Copy of
config/app.php
Copy of App\Http\Controllers\NewsController.php