Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PetroGromovo's avatar

How with calebporzio/sushi plugin fill data from other tables?

On Laravel/filament site I need using solutionforest/filament-tree pluging to create custom tree based on 3 tables tasks : =>tikets (has task_id field) =>ticket_user (user assigned to any tickets)

I make it with calebporzio/sushi plugin and reading docts at https://github.com/calebporzio/sushi I created TaskTicketReport model, which I want to fill with data at runtime :

<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TaskTicketReport extends Model
{
    use \Sushi\Sushi;

    protected $rows
        = [
            [
                'id' => 1,
                'parent_id' => 0,
                'title' => '1 : Mastering Laravel/vue.js',
            ],
            [
                'id' => 2,
                'parent_id' => 0,
                'title' => '2 : Develop Tasks management site using Laravel/vue.js',
            ],
        ];

    public function getRows()
    {
        return $this->rows;
    }
    public function addTaskTicketReport(array $rowArray)
    {
        $this->rows[] = $rowArray;
    }
}

And using this class:

$tasks = Task::getByActive(Task::STATUS_ACTIVE)
->orderBy('id', 'asc')
    ->get();
    
$newTaskTicketReport = new TaskTicketReport();
foreach ($tasks as $task) {
    $newTaskTicketReport->addTaskTicketReport(
        [
            'id' => $task->id,
            'parent_id' => 0,
            'title' => $task->title,
        ],
    );
}

$taskTicketReports                  = TaskTicketReport:://getByActive($this->checkOnlyActive)
    orderBy('id', 'asc')
    ->get();
echo print_r( $taskTicketReports->toArray(), true );

and result data are default rows in Model, not data from Task model, which I try to add to TaskTicketReport...

and what I see in sql tracing :

   SELECT * 
    FROM `tasks` 
    WHERE `status` = '1' 
    ORDER BY `id` asc 

How can I do it ?

Quotation from the docs :

Using ->getRows()

You can optionally opt out of using the protected $rows property, and directly implement your own getRows() method.

This will allow you to determine the rows for the model at runtime. You can even generate the model's rows from an external source like a third-party API.
    

all my code is withing 1 request, I use console command for easy testing...

"laravel/framework": "^9.52.10",
"filament/filament": "^2.17.49",
"filament/forms": "^2.17.49",
"calebporzio/sushi": "^2.4",

Thanks in advance!

0 likes
1 reply
PetroGromovo's avatar

Are there some different plugins/decisions for my goal?

Please or to participate in this conversation.