Comments (11)
@ryangjchandler yeah that's what I used for this simple use case and it makes sense as I can reuse this accessor. My other case was to build a popover for cell that shows a full user object on hover but I can most likely just do another query from the custom view with the user id there.
Hm, I'll take a look at this later on if I get a chance - see if there's any sensible way for us to do this.
from filament.
@zltn Here's what you want to do:
Text::make('myHasOneRelation')
->getValueUsing(function ($record) {
return $record->myHasOneRelation;
})
->formatUsing(function ($myHasOneRelation) {
return $myHasOneRelation->name;
})
If you have any questions, please feel free to re-open this issue and we can look at ways of improving the developer experience.
from filament.
Hey! Are you using the dot syntax to retrieve the display column from the related table?
e.g. Columns\Text::make('myHasOneRelation.name')
from filament.
I had a look to see if I could reproduce this and it seems to be the behaviour you would expect if you weren't trying to retreive a field, but the whole relationship.
Columns\Text::make('myHasOneRelation')
doesn't return anything, presumably as it's returning a model which can't be converted wheras Columns\Text::make('myHasManyRelation')
is returning a collection which will be converted to a JSON string
from filament.
@jamessessford Yeah, I can't see any reason why someone would need to retrieve the whole relationship, so I wouldn't say this is a bug more of an unexpected scenario.
@zltn If you want to show some information about the relation, you should use the dot-notation syntax as mentioned by @danharrin or you could also use an accessor on the model itself.
from filament.
@ryangjchandler definitely
from filament.
The dot syntax works and I can do a workaround for this model. My original approach was to pass on the entire object and use the formatUsing()
method on the entire object. @ryangjchandler this would be the big use case for which you'd want the entire object. Same for passing on the object to a custom view with view()
which I'm planning for another model.
from filament.
@zltn You can use an accessor to get your custom "formatted" data.
from filament.
@ryangjchandler yeah that's what I used for this simple use case and it makes sense as I can reuse this accessor. My other case was to build a popover for cell that shows a full user object on hover but I can most likely just do another query from the custom view with the user id there.
from filament.
Regarding the HasOne error:
Could you please explain with more detail? I mean, in which file or namespace in Filament Admin should I try?
In my case, in a ModelResource file, inside the
public static function form(Form $form): Form
{
return $form
->schema([
//a hasOne relationship defined in my model
Forms\Components\BelongsToSelect::make('myHasOneRelation')->relationship('myHasOneRelation','myHasOneRelation.id')->required()->helperText('ID '),//hasOne relationship
])
}
method, how do I implement a "hasOne" relationship in a create / edit form? Because I get the following error:
TypeError
Filament\Forms\Components\BelongsToSelect::getRelationship(): Return value must be of type ?Illuminate\Database\Eloquent\Relations\BelongsTo, Illuminate\Database\Eloquent\Relations\HasOne returned
from filament.
Moreover, I have a "BelongsToThrough" relationship, defined in my model like so:
public function myrelationship2(){
return $this->belongsToThrough(User::class,Event::class,'id','',[Event::class=>'event_id',User::class=>'responsable_id']);
}
How would I implement it inside my ModelResources "$form->schema()" and "$table->columns()"?
from filament.
Related Issues (20)
- Placeholder Content Not Updating HOT 1
- BulkAction Storage download not working for table in livewire component HOT 1
- Can't change page on a table HOT 10
- ![columnmapping](https://github.com/filamentphp/filament/assets/69535487/9a6fb3f9-dd31-444d-9c60-61969f804b32) HOT 2
- Bug in query builder on polymorphic relation HOT 1
- Import not Mapping the result HOT 2
- TypeError with Closure Parameter in `ClassAction` URL Definition with `assertTableActionHasUrl` Assertion HOT 11
- why formatStateUsing doesn't work in some cases? HOT 1
- formatStateUsing doesn't work HOT 1
- formatStateUsing doesn't work HOT 4
- Generating a slug from a title afterStateUpdated $set() HOT 2
- Using the builder and removing a block in code does not remove the content from the Record on subsequent save. HOT 5
- Database Notifications is not displayed correctly due to the ListPage parameter page=2 when the `$isPaginated` option is active HOT 3
- hiddenOn() and disabledOn() not working HOT 1
- Error when calling preserveFilenames function in Class Forms\Components\FileUpload HOT 1
- Modal Cancel Action Triggering on modal open not when it closes HOT 1
- Disabling 'attachFiles' does not prevent files from being attached (MarkdownEditor/RichEditor) HOT 1
- Relation manager action modal content page issue HOT 2
- Can't have medialibrary fields in two fieldsets for the same relationship in the same form HOT 4
- Summarizers\Sum Unable to count BelongsToMany intermediate table fields correctly HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from filament.