Reading manuals https://nova.laravel.com/docs/lenses/defining-lenses.html in Laravel 10 / nova 4.27 app I create a new lens with command
php artisan nova:lens Orders/MostActiveUsersWithProcessingOrders
and I fill methods of the created class app/Nova/Lenses/Orders/MostActiveUsersWithProcessingOrders.php (with loging code):
<?php
namespace App\Nova\Lenses\Orders;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\LensRequest;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Lenses\Lens;
class MostActiveUsersWithProcessingOrders extends Lens
{
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [];
/**
* Get the query builder / paginator for the lens.
*
* @param \Laravel\Nova\Http\Requests\LensRequest $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @return mixed
*/
public static function query(LensRequest $request, $query)
{
\Log::info(' -1 query ::');
return $request->withOrdering($request->withFilters(
$query->select(self::columns())
->join('orders', 'users.id', '=', 'orders.user_id')
->groupBy('users.id', 'users.name')
->withCasts([
'orders_count' => 'float',
])
), fn ($query) => $query->orderBy('orders_count', 'desc'));
}
/**
* Get the columns that should be selected.
*
* @return array
*/
protected static function columns()
{
\Log::info(' -1 columns ::');
return [
'users.id',
'users.name',
DB::raw('count(orders.id) as orders_count'),
];
}
/**
* Get the fields available to the lens.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
\Log::info(' -1 fields ::');
return [
ID::make('ID', 'id'),
Text::make('Name', 'name'),
Number::make('orders_count', 'orders_count', function ($value) {
return $value;
}),
];
}
/**
* Get the cards available on the lens.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function cards(NovaRequest $request)
{
\Log::info(' -1 cards ::');
return [];
}
/**
* Get the filters available for the lens.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function filters(NovaRequest $request)
{
\Log::info(' -1 filters ::');
return [];
}
/**
* Get the actions available on the lens.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function actions(NovaRequest $request)
{
\Log::info(' -1 actions ::');
return parent::actions($request);
}
/* Title of the card
*
* @return string
*/
public function name(): string
{
\Log::info(' -1 name ::');
return 'Active users with biggest number of processing orders';
}
/**
* Get the URI key for the lens.
*
* @return string
*/
public function uriKey()
{
\Log::info(' -1 uriKey ::');
return 'orders-most-active-users-with-processing-orders';
}
/**
* Determine if the given resource is authorizable.
*
* @return bool
*/
public static function authorize()
{
\Log::info(' -1 authorize ::');
return true;
}
}
As result I have no any data in Dashboard page(including text in name method).
Checking log I see only lines :
[2024-11-17 08:09:22] local.INFO: -1 authorize ::
[2024-11-17 08:09:22] local.INFO: -1 name ::
[2024-11-17 08:09:22] local.INFO: -1 uriKey ::
So methods query
, fields
, columns
are not even called. Why So ?
Additive info :
I added my MostActiveUsersWithProcessingOrders lens component into app/Nova/Dashboards/Main.php file as :
public function cards()
{
return [
// new OrdersInInvoiceWithExpireDate,
//
// new OrdersByStatusPieChart, new OrdersCompleted, new OrdersCompletedByManagerByDays,
// new NewReleases,
//
new MostActiveUsersWithProcessingOrders,
// new Help,
];
}
With this code my Dashboard
is empty. If I uncomment the rest components I see them on Dashboard
page.
MostActiveUsersWithProcessingOrders is the only Lens component and such problems only with it.
Looks like tp add custom data on dashboard page I need to create a new card with command like :
php artisan nova:card vendor/package
But not lense, as I tried