Bug report
My Setup
I have a Posts model and a Posts Type model. The posts model has a “post_type_id” field to store the relation.
On the Posts model, I declare the hasOne relation like so:
public function type()
{
return $this->hasOne('App\Models\PostType', 'id', 'post_type_id');
}
The Backpack Problem
In my Post CRUD Controller, I have the following under setupCreateOperation()
CRUD::addField([
'label' => "Type",
'type' => 'select',
'name' => 'post_type_id', // the db column for the foreign key
'entity' => 'type', // the relationship name in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
]);
When editing or creating a post, the form looks correct and I can see all the Post Types in the select box. Great!
The problem is that when I save the form I get an error:
Add [post_type_id] to fillable property to allow mass assignment on [App\Models\PostType].
The error makes no sense because “post_type_id” exists in the “Post” model (not PostType model) and it is fillable on the Posts model.
What am I do wrong?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Bug Definition & Meaning - Merriam-Webster
noun (1) · 1. a · 2. : an unexpected defect, fault, flaw, or imperfection · 3. a · 4. : a concealed...
Read more >Bug (2006) - IMDb
An unhinged war veteran holes up with a lonely woman in a spooky Oklahoma motel room. The line between reality and delusion is...
Read more >bug - Wiktionary
(entomology) An insect of the order Hemiptera (the “true bugs”). Any of various species of marine or freshwater crustaceans; e.g. a Moreton Bay...
Read more >Bug - Wikipedia
A terrestrial arthropod animal (with at least six legs). Insect, a six-legged arthropod · Covert listening device, used in surveillance, espionage and policing ......
Read more >Bug Definition & Meaning - Dictionary.com
The word bug is often used to refer to tiny creatures that crawl along, such as insects and even small animals that are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My apologies, the problem was actually quite obvious. I had the wrong field value in the belongsTo relationship. It was defined as id when it should have been post_type_id.
Hi @lucidlive
My suggestion is to have a look at Backpack/NewsCRUD package. You need to view it like:
Article
is your Posts. (Has a BelongsTo relation with Category)Category
is your Post Type.Check models, database schema and controllers as an example.
I am with @tabacitu on this one, I still think this is something related with a bad implementation rather than a Backpack bug.
If you find i am wrong and this a bug please re-open.
Wish you the best, Pedro