thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.78k stars 2.67k forks source link

custom realtionship attributes doesn't work until make bread for the model #4853

Open dmoradian opened 4 years ago

dmoradian commented 4 years ago

Version information

Description

custom realtionship attributes doesn't work until make bread for the model

After performing the steps mentioned in the link below https://voyager-docs.devdojo.com/customization/custom-realtionship-attributes

custom realtionship attributes doesn't work for the model and Not seen in the display fields for relationship in BREAD form. To solve this problem, just make a bread for your model.

fletch3555 commented 4 years ago

I'm not sure I understand the issue. Of course it doesn't work without BREAD, since it's sole purposes is to add fields to the BREAD.

fletch3555 commented 4 years ago

Also, Voyager 1.3.* does not support Laravel 7. Please make sure you're providing accurate version numbers.

dmoradian commented 4 years ago

For example, when we want to use the $ additional_attributes field that we created in the teacher model for the message table bread,

`namespace App;

use Illuminate\Database\Eloquent\Model;

class Teacher extends Model { protected $table = 'teacher'; public $additional_attributes = ['full_name'];

public function getFullNameAttribute()
{
    return "{$this->name} {$this->family}";
}

}`

See the photo at the link below: http://kiansite.ir/image-share/github00.png

we do not see the $ additional_attributes(full_name) title when selecting the display field in the message bread.

To solve this problem, just make a bread for teacher model.

See the photo at the link below: http://kiansite.ir/image-share/github01.png

I hope you understand my explanation. Thanks to you for Voyager

MrCrayon commented 4 years ago

To make it short additional attribute is not shown ~in the modal~ while creating a new ~relationship~ BREAD but only while editing it.

MrCrayon commented 4 years ago

I think I got it wrong, you are probably editing another BREAD like Students and you are saying additional attribute for Teachers doesn't appear if a BREAD for teacher hasn't been created.

Anyway as asked please provide correct version numbers. https://github.com/the-control-group/voyager/issues/4836#issuecomment-602634849

GetulioMR commented 3 years ago

I think I got it wrong, you are probably editing another BREAD like Students and you are saying additional attribute for Teachers doesn't appear if a BREAD for teacher hasn't been created.

Anyway as asked please provide correct version numbers. #4836 (comment)

Hi @MrCrayon, this is my first contribution here, and I don't know if I can complement this issue or need to create a new one. But same happens with me, and my environment is:

PHP: 7.4 Laravel: 8 Voyager: 1.x-dev

The scenario is exactly that you described above. In my case, I created the BREAD for my model that i needed the additional attribute to be used in the relationship on another BREAD and hidden it from the menu and restricted the user access using the roles. But I think its not clear in actual documentation that need. I propose that we can user additional attributes without the need of creating a BREAD for the model or specify that need in the docs to easy the way from future devs that needs to use it.