I am using the FormController
behavior for a controller. There is a delete
button (trash icon) in the Update
page which I need to hide for logged in users who are not superuser. I can remove the delete
button by simply removing its html from the update.htm
file:
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
</button>
But this will remove the delete button for all users. I only want to remove this button if the logged in backend user is not admin. How can I do this dynamically?
You can check if the user is superuser because your view has access to the user object
<?php if($this->user->is_superuser): ?>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
</button>
<?php endif; ?>