jeudi 12 mars 2020

Best practice for storing checkbox and textarea in Laravel

I have already seen a few different approaches for storing textarea and checkbox and then showing them on edit view and show view... but I am still not satisfied and would like to hear from You, how do you handle the unchecked checkbox and especially the textarea security on show and edit with some wysiwyg plugin like ckeditor or tinymce?

For example for checkboxes I am using this setter;

public function setActiveAttribute($value): void
{
    $this->attributes['active'] = $value ? 1 : 0;
}

Is this the best way to do it?

And for textarea on submit I allow everything and then on edit view I show it like this:

{!! Form::textarea($key, htmlentities($value), ['class' => 'form-control ckeditor-field']) !!}

and on show view I'm using a Purifier (link below) and I show it like this

{!! \Purifier::clean($value) !!}

So I just wanted to know what are the best practices? Is this fine what I'm doing?

https://github.com/mewebstudio/Purifier




Aucun commentaire:

Enregistrer un commentaire