CRUD relationship if is fillable doesn't detect the entry name #1221
-
So I have this Crud field:
Refers to a User model in eloquent but if in the model that has this field I set that value as fillable doesn't show anymore the name, if I remove from there yes. It should show in the List the user name and not the ID. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Based on the information provided in the knowledge sources, I can offer some insights into your issue with the CRUD relationship field not detecting the entry name. It seems that you're experiencing a problem similar to what others have reported, where the relationship field is displaying the ID instead of the desired attribute (in your case, 'name'). Here are a few suggestions based on the available information:
public function user()
{
return $this->belongsTo(User::class);
}
CRUD::field([
'label' => 'Sede',
'type' => 'relationship',
'name' => 'user', // Changed from 'user_id' to 'user'
'attribute' => 'name',
]);
CRUD::column([
'label' => 'Sede',
'type' => 'select',
'name' => 'user_id',
'entity' => 'user',
'attribute' => 'name',
'model' => "App\Models\User",
]);
CRUD::field([
'name' => 'user',
'type' => 'relationship',
'pivotSelect' => [
'attribute' => 'name'
],
// ... other options ...
]);
If none of these solutions work, it's possible that there might be a bug or a specific configuration in your setup that's causing this issue. In that case, you might want to create a new issue on the Backpack GitHub repository with more details about your setup and the exact behavior you're seeing. Remember, the behavior of relationship fields can sometimes be affected by the specific version of Backpack you're using, so make sure you're using the latest version and check the documentation for any changes in how relationship fields are handled. Relevant sources: Github Issue (closed): [Bug] On Relationship Field, the attribute 'attribute' doesn't work in Show View |
Beta Was this translation helpful? Give feedback.
Ok so addColumn was useless as the values where not changed.
This code worked.