Using backpack/crud: 5.6.0 and laravel 9 here and I want to prevent a user from creating more then n items via the admin’s ui "Add Environment" button with link https://example.com/admin/environment/create
When the user presses the button I want to show a simple message that the limit has been reached etc.
Where and how to implement this?
Thanks in advance for any suggestions.
Below are the routes for the Environment model:
GET|HEAD admin/environment .................................................................................................... environment.index › AdminEnvironmentCrudController@index
POST admin/environment .................................................................................................... environment.store › AdminEnvironmentCrudController@store
GET|HEAD admin/environment/create ........................................................................................... environment.create › AdminEnvironmentCrudController@create
POST admin/environment/search ........................................................................................... environment.search › AdminEnvironmentCrudController@search
PUT admin/environment/{id} ............................................................................................. environment.update › AdminEnvironmentCrudController@update
DELETE admin/environment/{id} ........................................................................................... environment.destroy › AdminEnvironmentCrudController@destroy
GET|HEAD admin/environment/{id}/details ..................................................................... environment.showDetailsRow › AdminEnvironmentCrudController@showDetailsRow
GET|HEAD admin/environment/{id}/edit ............................................................................................ environment.edit › AdminEnvironmentCrudController@edit
GET|HEAD admin/environment/{id}/show ............................................................................................ environment.show › AdminEnvironmentCrudController@show
2
Answers
Just stumbled upon https://laravel.com/docs/9.x/eloquent#events-using-closures and by using below function in the Environment model class it works.
you can use validations to prevent user create more than X elements, something like this: