> ## Documentation Index
> Fetch the complete documentation index at: https://nova.laravel.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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:

<CodeGroup>
  ```php Construct theme={null}
  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,
      ];
  }
  ```

  ```php Make theme={null}
  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(),
      ];
  }
  ```
</CodeGroup>

## 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:

```php app/Nova/User.php theme={null}
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:

```php theme={null}
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
            ),
    ];
}
```
