Okipa / laravel-table

Generate tables from Eloquent models.
MIT License
532 stars 64 forks source link

Problem referencing Foreign key in table #65

Closed pork94 closed 3 years ago

pork94 commented 3 years ago

I am having issue referencing a foreign key to the name.

The model structure is as follows:

I am now creating the teacher table to show the information associated with it including the class name. However i am only able to display the class ID(foreign key) instead of the class name.

I saw the custom value option and tried the following code to reference the name from the foreign ID via laravel eloquent relationship but to no avail.

$table->column('class')->value(function(Teacher $teacher) {
            return config('teacher.class' . $teacher->class->name);
});

Would appreciate any help!

Okipa commented 3 years ago

Hi @pork94, I would need to see you entire table configuration (class) in order to see exactly what could be going wrong.

You're solution should be working but you will not be able to sort or search results if you call ->value() or ->html() as it only formats the output and the SQL request will not be aware of what should be sorted or searched.

Okipa commented 3 years ago

@pork94, I'm closing this as the issue seems to be quite inactive.

Please comment this issue if you still struggle to do what you intend to.