You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This [Laravel Nova](https://nova.laravel.com/) package adds automated breadcrumbs to the top of Nova 4 resources.
3
+
This [Laravel Nova](https://nova.laravel.com/) package extends the breadcrumbs functionality of the First Party Nova breadcrumbs.
4
4
5
-
Version 1.x has breaking changes from 0.x for parent resource discovery. See the [issues section](#100-breaking-changes) for details.
5
+
Tests repo can be found here: https://github.com/Formfeed-UK/nova-breadcrumbs-tests
6
6
7
-
## Requirements
7
+
## Version 2.x Changes
8
+
9
+
Version 2.x is a significant change from previous versions, this package now augments the existing nova breadcrumbs to offer:
10
+
11
+
- Static methods on the breadcrumbs class allowing control of breadcrumb generation globally
12
+
- Methods on Resources allowing control of breadcrumb generation per resource (per-resource methods override static callbacks)
13
+
- Support for resource groups
14
+
- Nested resource breadcrumbs
15
+
16
+
#### Breaking changes from 1.x
17
+
- Will use the Nova 4.19+ Breadcrumbs Vue components
18
+
- No Longer uses resource cards (This gives better UX as the breadcrumbs will be sent via the page props as per the built in ones and drops a request)
19
+
- Will intercept the Nova Breadcrumbs via middleware
20
+
- Can no longer have custom CSS (due to using the Nova components)
21
+
- Can no longer use the onlyOn{view}, exceptOn{view} etc permissions methods. Breadcrumb visibility can now be controlled via the callbacks/class methods
22
+
- Each breadcrumb will extend the Nova Breadcrumb class, and the array of Breadcrumbs will extend the Nova Breadcrumbs class.
23
+
24
+
## Requirements >= v2.x
25
+
26
+
-`php: >=8.0`
27
+
-`laravel/nova: ^4.19`
28
+
29
+
## Requirements <= v1.x
8
30
9
31
-`php: >=8.0`
10
32
-`laravel/nova: ^4.0`
@@ -21,10 +43,8 @@ It supports:
21
43
- Linking directly to Resource Tabs in the [eminiarts/nova-tabs](https://github.com/eminiarts/nova-tabs) package (Tab slugs are recommended)
22
44
- Linking to either the resource's index or its parent (for relationships included as fields)
23
45
- Customising the title and label functions for resources
24
-
- Specifying custom css classes
25
46
- Use on Dashboards (only to the extent that the Breadcrumbs show as `Home -> {Current Dashboard}`). Mainly for UI consistency.
26
-
27
-
This package relies on [formfeed-uk/nova-resource-cards](https://github.com/Formfeed-UK/nova-resource-cards) which wrap a number of nova pages. If you override these pages yourself ensure that nova-resource-cards is loaded after the packages which do so.
47
+
- Methods/Callbacks to control the breadcrumbs generation global or per resource
1)Include the breadcrumbs card at the beginning of the cards array in any resources that you wish to use breadcrumbs (be sure to include `$this` as the second parameter):
66
+
1)Enable Nova Breadcrumbs in the same way as the first party Nova Breadcrumbs in your `NovaServiceProvider``boot` method:
47
67
48
68
```php
49
-
...
50
69
51
-
use Formfeed\Breadcrumbs\Breadcrumbs;
70
+
public function boot() {
71
+
parent::boot();
52
72
53
-
class MyResource extends Resource {
54
-
...
55
-
public function cards(NovaRequest $request) {
56
-
return [
57
-
Breadcrumbs::make($request, $this),
58
-
...
59
-
];
73
+
Nova::withBreadcrumbs(true);
60
74
}
61
-
...
62
-
}
75
+
63
76
```
64
-
This card extends `ResourceCard` from that package and as such has the visbility and authorisation methods available.
65
77
66
78
2) Optionally configure a `parent` method on your Model to explicitly define the relationship the package should query. The name of this function can be changed in the configuration file.
67
79
@@ -84,35 +96,85 @@ class MyModel extends Model {
84
96
}
85
97
```
86
98
87
-
### Include in all Resources
99
+
### Resource Methods
100
+
101
+
You can optionally override the default behaviour of the breadcrumbs package on a per resource basis by adding methods to your Nova Resource. These methods should all return an instance of Breadcrumb or an array of Breadcrumb instances.
102
+
103
+
-`groupBreadcrumb(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $groupBreadcrumb)` - Override the group breadcrumb for this resource
104
+
-`indexBreadcrumb(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $indexBreadcrumb)` - Override the index breadcrumb for this resource
105
+
-`detailBreadcrumb(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $detailBreadcrumb)` - Override the detail breadcrumb for this resource
106
+
-`formBreadcrumb(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $formBreadcrumb, $type)` - Override the form breadcrumb for this resource, $type is a string referring to the current form type (create, update, attach, replicate etc)
107
+
-`resourceBreadcrumbs(NovaRequest $request, Breadcrumbs $breadcrumbs, array $breadcrumbArray)` - Override the entire set of breadcrumbs for this resource
88
108
89
-
If you would like to include the Breadcrumbs on all resources in one place, the best way to do this is to override the `resolveCards` method on your `App/Nova/Resource.php` file, as by default this file is extended by all of the Nova resources in your Application.
109
+
For Dashboards, you can use the following method:
90
110
91
-
A very basic example could look like this:
111
+
-`dashboardBreadcrumb(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $dashboardBreadcrumb)` - Override the dashboard breadcrumb for this resource
112
+
113
+
#### Example
92
114
93
115
```php
94
-
public function resolveCards(NovaRequest $request)
public function groupBreadcrumb(NovaRequest $request, Breadcrumbs $breadcrumbs, Breadcrumb $groupBreadcrumb) {
132
+
return null;
99
133
}
134
+
}
135
+
100
136
```
101
137
102
-
### Usage on Dashboards
138
+
### Static Callbacks
139
+
140
+
You can override the default behaviour of the breadcrumbs globally by using the following static methods on the Breadcrumbs class. They should be provided within a boot method on a service provider.
103
141
104
-
Simply include the Breadcrumbs at the start of the Cards array for your dashboard. You'll need to include the request manually, as its not available on the Dashboard cards method.
142
+
These methods will be overriden by any per resource methods.
105
143
106
-
For example for the default Dashboard:
144
+
The closure provided should return either an instance of Breadcrumb or an array of Breadcrumb instances.
Please see the [formfeed-uk/nova-resource-cards](https://github.com/Formfeed-UK/nova-resource-cards) package for information on the visbility and authorisation methods. They broadly follow the same pattern as fields.
141
-
142
196
#### Invoking Reflection
143
197
Determining the parent via invoking reflected blank model methods and checking the returned type is now disabled by default.
144
198
@@ -159,22 +213,6 @@ You can also set this on a per-resource basis with the following static:
159
213
160
214
If you have any requests for functionality or find any bugs please open an issue or submit a Pull Request. Pull requests will be actioned faster than Issues.
161
215
162
-
### 1.0.0 Breaking Changes
163
-
164
-
1.0.0 introduces a breaking change in how the parent model is determined. The following is now applied in order:
165
-
166
-
1) Attempt to get parent from the model method with name retrieved from `parentMethod` config option
167
-
2) Attempt to get parent from the first `Laravel\Nova\Fields\BelongsTo` field in your resource
168
-
3) Attempt to get parent from the first method on your model that has a defined return type of `Illuminate\Database\Eloquent\Relations\BelongsTo`
169
-
170
-
If none of these are fulfilled the package now optionally (defaulting to false):
171
-
172
-
4) Attempt to find a `Laravel\Nova\Fields\BelongsTo` relationship via creating a blank model, invoking it's methods, and checking the type of the return.
173
-
174
-
This was previously turned on by default if the `parentMethod` was not found, and had the potential to be destructive if there were methods on the model which were destructive across all records, such as `Model::truncate()`
175
-
176
-
Please see the [**Configuration Options**](#invoking-reflection) section for more details on how to enable this functionality.
177
-
178
216
## License
179
217
180
218
Nova Breadcrumbs is open-sourced software licensed under the [MIT license](LICENSE.md).
0 commit comments