How to set badge color from relation
How to set badge color from relation many to many
19 Replies
`
always return success
What does dd($schools->contains(…)) give you? Perhaps the logic isn’t returning what you expect?
@justlasse return true
i need that the badge of the current school be success else primary
If it returns true then the code is working correctly. But if you expect it to return false then something else is wrong
Try to manually manipulate the data so that the statement returns false for the contains and see if that works
@justlasse I think it applies the first return on all elements not element by element
Ah you have multiple badges yes then i believe it’s a different approach
how can i do that ??
I think you need a different type of column
Since the textcolumn assumes 1 value
ok
I will think of another approach perhaps with ->state()
thanks
You could use the badge component in a custom column perhaps?
Here is the problem that you're up against in the textcolumn....
You can inject $state in the color function
that returns the current badge "school" in your instance
So perhaps if you format the state and use commercial_name, but use the actual schools relation in the make, you'd have access to the current school object
This actually worked in the textcolumn, no custom column needed
@justlasse thanks a lot it's work
NICE!
If you want more colors you can just make it a match statement to return multiple results and a default.
for example
You can inject a model in my instance Story to the function, but you have to call it $state or it doesn't seem to work.
Even better! Thanks for adding that
done thank you