Skip to main content
Glama
brianirish

Laravel 12 Docs MCP Server

by brianirish
registering-lenses.md4.79 kB
# Nova - Lenses/Registering-Lenses *Source: https://nova.laravel.com/docs/v5/lenses/registering-lenses* --- - [Community](https://discord.com/invite/laravel) - [Blog](https://blog.laravel.com) ##### Get Started - [Installation](/docs/v5/installation) - [Release Notes](/docs/v5/releases) - [Upgrade Guide](/docs/v5/upgrade) ##### Resources - [The Basics](/docs/v5/resources/the-basics) - [Fields](/docs/v5/resources/fields) - [Dependent Fields](/docs/v5/resources/dependent-fields) - [Date Fields](/docs/v5/resources/date-fields) - [File Fields](/docs/v5/resources/file-fields) - [Repeater Fields](/docs/v5/resources/repeater-fields) - [Field Panels](/docs/v5/resources/panels) - [Relationships](/docs/v5/resources/relationships) - [Validation](/docs/v5/resources/validation) - [Authorization](/docs/v5/resources/authorization) ##### Search - [The Basics](/docs/v5/search/the-basics) - [Global Search](/docs/v5/search/global-search) - [Scout Integration](/docs/v5/search/scout-integration) ##### Filters - [Defining Filters](/docs/v5/filters/defining-filters) - [Registering Filters](/docs/v5/filters/registering-filters) ##### Lenses - [Defining Lenses](/docs/v5/lenses/defining-lenses) - [Registering Lenses](/docs/v5/lenses/registering-lenses) ##### Actions - [Defining Actions](/docs/v5/actions/defining-actions) - [Registering Actions](/docs/v5/actions/registering-actions) ##### Metrics - [Defining Metrics](/docs/v5/metrics/defining-metrics) - [Registering Metrics](/docs/v5/metrics/registering-metrics) ##### Digging Deeper - [Dashboards](/docs/v5/customization/dashboards) - [Menus](/docs/v5/customization/menus) - [Notifications](/docs/v5/customization/notifications) - [Authentication](/docs/v5/customization/authentication) - [Impersonation](/docs/v5/customization/impersonation) - [Tools](/docs/v5/customization/tools) - [Resource Tools](/docs/v5/customization/resource-tools) - [Cards](/docs/v5/customization/cards) - [Fields](/docs/v5/customization/fields) - [Filters](/docs/v5/customization/filters) - [CSS / JavaScript](/docs/v5/customization/frontend) - [Assets](/docs/v5/customization/assets) - [Localization](/docs/v5/customization/localization) - [Stubs](/docs/v5/customization/stubs) On this page - [Authorization](#authorization) Lenses # Registering Lenses Learn how to register lenses in your Nova application. Once you have defined a lens, you are ready to attach it to a resource. Each resource generated by Nova contains a `lenses` method. To attach a lens to a resource, you should simply add it to the array of lenses returned by this method: Construct Make Copy Ask AI ``` use Laravel\Nova\Http\Requests\NovaRequest; // ... /** * Get the lenses available for the resource. * * @return array<int, \Laravel\Nova\Lenses\Lens> */ public function lenses(NovaRequest $request): array { return [ new Lenses\MostValuableUsers, ]; } ``` ## [​](#authorization) Authorization If you would like to only expose a given lens to certain users, you may invoke the `canSee` method when registering your lens. The `canSee` method accepts a closure which should return `true` or `false`. The closure will receive the incoming HTTP request: app/Nova/User.php Copy Ask AI ``` use App\Models\User as UserModel; use Laravel\Nova\Http\Requests\NovaRequest; // ... /** * Get the lenses available for the resource. * * @return array<int, \Laravel\Nova\Lenses\Lens> */ public function lenses(NovaRequest $request): array { return [ Lenses\MostValuableUsers::make() ->canSee(function ($request) { return $request->user()->can( 'viewValuableUsers', UserModel::class ); }), ]; } ``` In the example above, we are using Laravel’s `Authorizable` trait’s `can` method on our `User` model to determine if the authorized user is authorized for the `viewValuableUsers` action. However, since proxying to authorization policy methods is a common use-case for `canSee`, you may use the `canSeeWhen` method to achieve the same behavior. The `canSeeWhen` method has the same method signature as the `Illuminate\Foundation\Auth\Access\Authorizable` trait’s `can` method: Copy Ask AI ``` use App\Models\User as UserModel; use Laravel\Nova\Http\Requests\NovaRequest; // ... /** * Get the lenses available for the resource. * * @return array<int, \Laravel\Nova\Lenses\Lens> */ public function lenses(NovaRequest $request): array { return [ Lenses\MostValuableUsers::make() ->canSeeWhen( 'viewValuableUsers', User::class ), ]; } ``` Was this page helpful? YesNo [Defining Lenses](/docs/v5/lenses/defining-lenses)[Defining Actions](/docs/v5/actions/defining-actions) ⌘I

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/brianirish/laravel-docs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server