Giter Club home page Giter Club logo

Comments (7)

mortezarajabi avatar mortezarajabi commented on June 17, 2024 4

I had the same issue, and I tried to add the inverse of relation on my child item resource.

For the Posts example, I have the following on my Post resource.

BelongsTo::make(__('User'), 'user', User::class),

This fixed the issue.

from laravel-nova-nested-form.

jangidgirish avatar jangidgirish commented on June 17, 2024 2

Yes, it's working fine after inverse relations.👍

from laravel-nova-nested-form.

yassilah avatar yassilah commented on June 17, 2024

Did you set this in yout BotWhiteListIp model?

protected $primaryKey = 'bot_white_list_id';

from laravel-nova-nested-form.

jangidgirish avatar jangidgirish commented on June 17, 2024

bot_white_list_id is foreign key of bot_white_lists table, i think it should auto fill from parent resource model on save update?

this is table structure

mysql> DESCRIBE bot_white_lists;
+-----------------+------------------+------+-----+---------+----------------+
| Field           | Type             | Null | Key | Default | Extra          |
+-----------------+------------------+------+-----+---------+----------------+
| id              | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| name            | varchar(255)     | NO   |     | NULL    |                |
| homepage_url    | varchar(255)     | YES  |     | NULL    |                |
| agent           | varchar(255)     | NO   |     | NULL    |                |
| created_at      | datetime         | NO   |     | NULL    |                |
| updated_at      | datetime         | YES  |     | NULL    |                |
+-----------------+------------------+------+-----+---------+----------------+
mysql> describe bot_white_list_ips;
+-------------------+------------------+------+-----+---------+----------------+
| Field             | Type             | Null | Key | Default | Extra          |
+-------------------+------------------+------+-----+---------+----------------+
| id                | int(11)          | NO   | PRI | NULL    | auto_increment |
| bot_white_list_id | int(10) unsigned | NO   | MUL | NULL    |                |
| ip                | varchar(128)     | NO   |     | NULL    |                |
| created_at        | datetime         | YES  |     | NULL    |                |
| updated_at        | datetime         | NO   |     | NULL    |                |
+-------------------+------------------+------+-----+---------+----------------+

i have added hasMany relation in BotWhiteList model of BotWhiteListIps model, and the NestedForm field has attached in BotWhiteList resource, so it should auto fill when BotWhilteList is create. but this is returning error

SQLSTATE[HY000]: General error: 1364 Field 'bot_white_list_id' doesn't have a default value (SQL: insert into bot_white_list_ips (ip, updated_at, created_at) values (127.0.0.1, 2019-02-17 09:41:20, 2019-02-17 09:41:20))

Auto populated items is updating fine but when i add new item then error is show up.
Is there way, i can fill bot_white_list_id value before create or update for add new items

from laravel-nova-nested-form.

yassilah avatar yassilah commented on June 17, 2024

OK, are you able to fetch your related bot_ips outside of this package? I'm not sure but I think you should set your relationship as follows:

public function bot_ips () {
      return $this->hasMany(BotWhiteListIp::class, 'bot_white_list_id', 'id');
}

from laravel-nova-nested-form.

jangidgirish avatar jangidgirish commented on June 17, 2024

thank you for your reply, i think, the relationship is already setup accordingly
image
foreignKey, localKey is auto populating by naming convention

The relation filed is working fine with Nova HasMany field, but it's providing option on view page, but i would like to add more option in same form
image

from laravel-nova-nested-form.

nilsE avatar nilsE commented on June 17, 2024

@mortezarajabi thanks man!

from laravel-nova-nested-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.