question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lucidlivecommented, Jul 20, 2020

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.

0reactions
pxpmcommented, Jul 20, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found