So I have a License model created through the octoberCMS builder with the List and Form views.
The license model contains one relation to School model.
Under the Form view there is a dropdown list with schools and an input field (type=number) which defines how many Licenses to create for the chosen school.
The default behaviour creates only 1 license
How to create the entered amount of licenses instead?
You need to override default behaviour.
In your controller you need to add this method.
here we initialise required variables so we can get data which were filled in text box, this is default code so i just copied it from core code.
once we have our $data variable we can access filled data we use
$data['license_to_create']
in your case its 100, and$data['school_id']
for which school you need to create license, Note: you may have different fields please change accordingly.validation step *optional, you can add some checks here and stop flow if something is not correct with error message.
loop to create new records for license modal ,[ default code will create only 1 record], but here we create it based on given count
$data['license_to_create']
just normal success message.
redirect where we need to redirect normally you need to redirect it to
/author-name/plugin-name/license-controller
Note: you may have different url please change accordingly.please add comment if you have any doubt.