This Laravel Nova package adds the functionality to add Resource Cards at the top of pages.
I consider this package feature complete, however I am open to feature requests and pull requests, if there's something you'd like to see feel free to submit an issue.
php: >=7.4
laravel/nova: ^4.0
This package wraps the following Laravel Nova pages and adds the ability to display Resource Cards above them:
- Index
- Detail
- Create
- Update
- Attach
- Update Attached
- Replicate
- Lens
- Dashboard
As the package is wrapping the pages, it should be fairly robust with regards to Nova Updates.
This package also includes more fine grained control over the pages the cards are displayed on, following the same logic as is used for Fields:
- showOnIndex
- showOnDetail
- showOnCreating
- showOnUpdating
- showOnPreview
- showOnAttach
- showOnReplicate
- showOnLens
- showOnDashboard
- hideFromIndex
- hideFromDetail
- hideFromDashboard
- hideFromLens
- hideWhenCreating
- hideWhenUpdating
- hideWhenAttaching
- hideWhenReplicating
- onlyOnIndex
- onlyOnDetail
- onlyOnForms (Now includes Attach and Replicate)
- onlyOnLens
- onlyOnDashboard
- exceptOnForms (Now includes Attach and Replicate)
Cards should extend the included ResourceCard
class rather than the standard class, but otherwise can be used like regular cards.
Install the package in to a Laravel app that uses Nova via composer:
composer require formfeed-uk/nova-resource-cards
-
Create a card according to the Nova Documentation (or use an existing card if you wish to convert it to ResourceCards).
-
Update your Card to extend ResourceCard instead of Card:
// MyResourceCard.php
...
use Formfeed\ResourceCards\ResourceCard;
class MyResourceCard extends ResourceCard {
...
}
- Then simply include it like a normal card within your resource:
// MyNovaResource.php
use App\MyResourceCard;
...
class MyNovaResource extends Resource {
...
public function cards(NovaRequest $request) {
return [
MyResourceCard::make($request)
];
}
...
}
Optionally chain visibility and authorisations:
public function cards(NovaRequest $request) {
return [
MyResourceCard::make($request)
->onlyOnForms()
->canSee(function ($request) {
return $request->user()->role === "admin";
}),
];
}
It's that simple!
There are a number of parameters available to your card, depending on the page the card is currently on. These parameters are available on the request object as query parameters.
Note: Just because these parameters are available doesn't mean they will be populated for any given request.
- resourceName
- display: "index"
- resourceName
- resourceId
- display: "detail"
- resourceName
- viaResource
- viaResourceId
- viaRelationship
- display: "create"
- resourceName
- resourceId
- viaResource
- viaResourceId
- viaRelationship
- display: "update"
- resourceName
- resourceId
- viaResource
- viaResourceId
- viaRelationship
- display: "replicate"
- resourceName
- resourceId
- viaResource
- viaResourceId
- viaRelationship
- parentResource
- polymorphic
- formUniqueId
- relatedResourceName
- display: "attach"
- resourceName
- resourceId
- viaResource
- viaResourceId
- viaRelationship
- parentResource
- polymorphic
- formUniqueId:
- relatedResourceName
- relatedResourceId
- viaPivotId
- display: "updateAttached"
- resourceName
- lens
- display: "lens
- resourceName: Dashboard Name
- display: "dashboard"
Nova Resource Cards is open-sourced software licensed under the MIT license.