'How to create custom column for polymorphic model and without model id in Laravel
I have a model to take the polymorph association "Qualification."
Qualification:
- id
- model_name
- name
- value
The Laravel documentation said that "_type" takes the model name and "_id" the id but with a table like above. My first question is: is there a way to tell laravel that I want to change the "_type" by "_name"? So my second is that I want to insert data now, but I don't have the "id" to place. I want to insert the model_name, for example:
model_name => "building"
name => "building type"
value => "chalet"
All documentation I read said that we need to find the data by id first Model::find(id);
And after that, we can insert the morph relation; but here, I don't have any id, just the model.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|