Mar 12, 2022
0
Level 2
Relational Metrics
I have a helpdesk and have teams table resources. There is a many to many relationship. A Technician can have many helpdesks. I already have the resource and technicians are assigned.
HelpdeskTeamHasManyHelpDesk
public function up()
{
Schema::create('help_desk_teams_has_help_desks', function (Blueprint $table) {
$table->bigInteger('help_desk_team_id')->unsigned()->index();
$table->foreign('help_desk_team_id')->references('id')->on('helpdesk_teams')->onDelete('cascade');
$table->bigInteger('help_desk_id')->unsigned()->index();
$table->foreign('help_desk_id')->references('id')->on('helpdesk')->onDelete('cascade');
$table->timestamps();
});
There are few technicians. I want the metric to simply count how many tasks do the technicians have.
/**
* Calculate the value of the metric.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return mixed
*/
public function calculate(NovaRequest $request)
{
return $this->count($request, HelpDeskTeamHasHelpDesks::where('help_desk_team_id', HelpDeskTeam::class)->with('helpdesk'),'technician_name','help_desk_team_id')->label(function ($value) {
return $value . ' Technicians';
});
}
Please or to participate in this conversation.