Closed awsqed closed 3 years ago
This isn't a package issue. You'll need to find some way to load your model from the repository inside your breadcrumbs file, likely copying logic you already have inside your controller.
This isn't a package issue. You'll need to find some way to load your model from the repository inside your breadcrumbs file, likely copying logic you already have inside your controller.
Sorry but I'm quite new. What I see here is it is the same implementation but two different outcomes, only difference is whether the Breadcrumbs::current()->title
is called or not.
I can still render the breadcrumb if I remove the mentioned method, so pretty sure the model is passed and loaded correctly. So there's no need to load it again when defining the breadcrumb.
Unfortunately, you will need to load the model again within your breadcrumbs file unless you find some other way to share data between breadcrumbs and your controller.
As you have demonstrated with your dd
s, the same data being passed to your controller method is the exact same data being passed to the breadcrumb method. Since you switched to the repository method, both methods are getting an ID string instead of the model.
To make this more "Eloquent," you might consider customizing Laravel's route-model binding to work with your repository.
https://laravel.com/api/8.x/Illuminate/Database/Eloquent/Model.html#method_resolveRouteBinding
Documentation is sparse, but a few quick internet searches should get you on the right track.
Internally, I'm not sure how Laravel does its own route-model binding in terms of duplicate database requests (in this case, between breadcrumbs and your controller). I'd hope they do some sort of caching, but it's quite possible duplicate requests are happening anyway.
Hope that helps.
It was working just find when I was using route-model binding and
Breadcrumbs::current()->title
returns the correct title. But after switching to repository design pattern, now the$model
object is just the normal ID of the model (I tried to dump the$model
object).This is the error I'm getting:
breadcrumbs.php
: https://controlc.com/bfa32022Controller:
View: https://controlc.com/e57d6f00
dd($model)
withBreadcrumbs::current()->title
:dd($model)
withoutBreadcrumbs::current()->title
: