F
Filament10mo ago
This PC

How can I save different data in one form to different databases?

In the bill form, I want to add the values ​​bill_id, table_id of bill_tables, dish_id and quantity of order_details, ...
No description
11 Replies
Dennis Koch
Dennis Koch10mo ago
If they are all relationships, you can use fields that support relationships like Select, Repeater and Layout fields
This PC
This PC10mo ago
Grid::make() ->schema([ Fieldset::make('Thông tin thanh toán') ->schema([ Select::make('bill_id') ->label('Bàn') ->relationship('table', 'name') ->placeholder('Tên bàn') ->required() ->model(BillTable::class), Select::make('staff_id') ->label('Người thanh toán') ->nullable() ->relationship('user', 'name') ->placeholder('Người thanh toán') ->required() ->model(BillTable::class) ]), ]), Tại sao tôi không thể lưu bill_tables vào cơ sở dữ liệu?
toeknee
toeknee10mo ago
english?
This PC
This PC10mo ago
Oh I'm so sorry Why can't I save bill_tables to the database?
This PC
This PC10mo ago
No description
Dennis Koch
Dennis Koch10mo ago
I doubt that billTables is a HasOne relationship
This PC
This PC10mo ago
Here are my 3 models and their relationships
No description
No description
No description
Dennis Koch
Dennis Koch10mo ago
Yes. As I said: No HasOne relationship. You cannot put a HasMany in a fieldset (single record)
This PC
This PC10mo ago
In the table and bill model I have changed the relationship to hasOne, but I still cannot save the data to the bill_table database.
No description
Dennis Koch
Dennis Koch10mo ago
You can just change relationship types how you want. Relationships require a certain database structure. HasOne is something totally different than HasMany. You should define the relationships like required and if evertyhing works in Laravel then hook it up to Filament. The Field for a HasMany would be a Repeater.
This PC
This PC10mo ago
After researching a lot from 7pm until now, with your dedicated help, I have succeeded. I don't know what else to say. I really appreciate your help.
Want results from more Discord servers?
Add your server