2

I have two tables Advisors and AdvisorRegions and the relation looks like this. One advisorRegion has many advisors and one advisor has one advisorRegion.

Now I want to show the name of the advisorRegion in the advisors-resource table.

I have the advisors_region_id as an foreign key in my advisor table

How do i do this in filament php v3.

I tried to look it up but found nothng interesting at all.

1
  • "I tried to look it up but found nothng interesting at all." - really? you should start from what you tried to do, and post any code in the question that may help people help you. read this stackoverflow.com/help/how-to-ask Commented Aug 25, 2023 at 11:25

2 Answers 2

4

From the Displaying data from relationships section of the docs:

TextColumn::make('advisorsRegion.name');

Where advisorsRegion is the name of the relationship in your model

Sign up to request clarification or add additional context in comments.

Comments

0

First define the relationship in the form section of the Model Resource.

Forms\Components\Select::make('vendor_id')
                ->relationship('vendor', 'company_name') // company_name or whatever field from the Vendor model

Then use the relation to display columns in table,

Tables\Columns\TextColumn::make('vendor.company_name')
                ->sortable()
                ->default(''),

Note: There should be a belongsTo relation defined in your model of the Model Resource. In this case

public function vendor()
{
    return  $this->belongsTo(Vendor::class);
}

within my Coupon model.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.