MenuItem link for lens #4280
Replies: 4 comments 3 replies
-
|
Agree, but it's a little tricky since lenses can be used on multiple resources (they are similar to filters in this regard). They are not explicitly tied to an individual resource. |
Beta Was this translation helpful? Give feedback.
-
|
FWIW - I've created a method in my /**
* @param class-string<Lens> $lens
* @param class-string<Resource> $resource
*/
private static function resourceLensUrl(string $lens, string $resource): string
{
return "/resources/{$resource::uriKey()}/lens/{$lens::make()->uriKey()}";
}// ...
MenuItem::link(__('Link Title'), path: self::resourceLensUrl(
MyLens::class,
MyResource::class,
));Figuring out a more permanent solution to call directly on a |
Beta Was this translation helpful? Give feedback.
-
|
Here is my solution: <?php
namespace App\Nova\Support\Menu;
use Laravel\Nova\Lenses\Lens;
class MenuItem extends \Laravel\Nova\Menu\MenuItem
{
public static function lens($resourceClass, $lensClass): self
{
/** @var Lens $lens */
$lens = new $lensClass;
return self::resource($resourceClass)
->path('/resources/'.$resourceClass::uriKey().'/lens/'.$lens->uriKey())
->name($lens->name());
}
} |
Beta Was this translation helpful? Give feedback.
-
|
@davidhemphill thanks for implementing! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be great to me able to pass lens class as a second param to
MenuItem::resource()to add the menu link to resource lens.Beta Was this translation helpful? Give feedback.
All reactions