PetroGromovo's avatar

How to run some laravel script before resource is opened ?

On laravel 11 / nova 4 app I created a orders_report table, which I want to fill manually from some laravel script with data based on orders of the site.

I added menu item as :

    MenuSection::make('Reports', [
        ...
        MenuItem::resource(OrdersReport::class),
    ]),

and resource declaration :

<?php

namespace App\Nova\Reports;

use App\Nova\Resource;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;

class OrdersReport extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var class-string<\App\Models\OrderReport>
     */
    public static $model = \App\Models\OrderReport::class;
   ...

In which way can I run laravel script(supposedly action class) to fill orders_report table before this resource is opened ?

1 like
4 replies
vincent15000's avatar

Not sure to understand what you need.

If you want to fill this table with datas from the database, you probably need to create a database view.

PetroGromovo's avatar

@vincent15000 , a database view is not good decision - as data in the table would have some calculative data, which must be done on laravel side.

1 like
PetroGromovo's avatar

@me108 , Sorry, if I poor explained what I want : I need to run some action when User clicked on menu - So open page would show some message : "Data are collection" and after script has finished the job to open the report with data. In common laravel I could you __construct for this.

1 like

Please or to participate in this conversation.