how can you create languages with level in laravel backpack? #264
-
My "languages" column I want that when I click save, there should be several records in the database. I want to create one action, many entries in the database. I write the name of the language database: id | title | level 1 | English | A1 - Primary 2 | English | A2 - Elementary 3 | English | B1 - Medium |
Beta Was this translation helpful? Give feedback.
Replies: 0 comments 7 replies
-
@tabacitu help me please |
Beta Was this translation helpful? Give feedback.
-
Hello @Bekzhan99 Cheers |
Beta Was this translation helpful? Give feedback.
-
@pxpm can you give examples? I'm new and I don't understand |
Beta Was this translation helpful? Give feedback.
-
Well @Bekzhan99 I recommend you start by learning the basics: https://laravel.com/docs/9.x/eloquent#events , so basically what you want is listening to the If your process is more complex you can totally overwrite the crud save process by overwritting the crud store/update functions: https://backpackforlaravel.com/docs/5.x/getting-started-crud-operations#callbacks-1 that way you have total control on what is going to be created/updated, create related models yourself etc etc. Sorry can't be much more help here, this should be straigthfoward to follow. |
Beta Was this translation helpful? Give feedback.
-
@Bekzhan99 you are using two distinct events types, you can use any of them, but both of them is overkill I think. From your example, if you want is to the user to be able to select a language and a level for that language, I think you should be doing the following: Create a table with all the languages (create a migration and a seeder to seed all the languages in a table in the database). Create a new table where you will hold the relation with user/languages like In the end the user should be able to select one or more languages and for each one choose a level. No need for events or anything extra. Cheers |
Beta Was this translation helpful? Give feedback.
@Bekzhan99 you are using two distinct events types, you can use any of them, but both of them is overkill I think.
From your example, if you want is to the user to be able to select a language and a level for that language, I think you should be doing the following:
Create a table with all the languages (create a migration and a seeder to seed all the languages in a table in the database). Create a new table where you will hold the relation with user/languages like
languages_user
with columns:user_id, language_id, level
. Configure the relations in user and language models, they should bebelongsToMany
. Use arepeatable
field in the user controller (or where you want to select the languag…