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, ...
11 Replies
If they are all relationships, you can use fields that support relationships like Select, Repeater and Layout fields
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?
english?
Oh I'm so sorry
Why can't I save bill_tables to the database?
I doubt that
billTables
is a HasOne
relationshipHere are my 3 models and their relationships
Yes. As I said: No
HasOne
relationship. You cannot put a HasMany in a fieldset (single record)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.
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.
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.