amaelftah/laravel-trix

trix values does not get saved

rabol opened this issue · 8 comments

rabol commented

My Model is like this:

class Form extends Model
{
    use HasTrixRichText;

    protected $fillable = [
        'form_id',
        'title',
        'description',
    ];

    protected $guarded = [];
}

blade like this:

<div class="form-group">
  <label class="required" for="content">{{ trans('cruds.form.fields.content') }}</label>
  @trix(\App\Form::class, 'content')
  @if($errors->has('content'))
    <span class="text-danger">{{ $errors->first('content') }}</span>
  @endif
  <span class="help-block">{{ trans('cruds.form.fields.content_helper') }}</span>
</div>

Controller like this:

$data = $request->all();
$data['form_id'] = NumberSequence::getNextNum('forms');
$form = Form::create($data);

nothing get save to the DB

@rabol can you try to remove the $fillable from your model

rabol commented

its is not in my fillable

but... I managed to get it working by adding
form-trixFields to the $fillable

@rabol ok cool i will close the issue since it's fixed

rabol commented

No, it's not fixed, it's a work-around.
According to the documentation one should not add the field to the $fillable

@rabol if you removed $fillable totally and set $guarded as [] it should work

rabol commented

hm... I'll find another solution as $fillable is a 'Laravel' thing I like for security

@rabol ok got it i think we will need to add this to the documentation

@amaelftah
Yes please add this to the documentation of this excellent tool.

protected $fillable = ['title', 'post-trixFields', 'attachment-post-trixFields']; // add both trixFields to $fillable

Spent a couple of hours thinking that it didn't work. Many (most?) models will have a $fillable property and any that do won't save the field unless it's added.