Forbidden when edit richtext
Hello!
I just deployed my Laravel project with Filament, but I'm having a problem with RichText. When I edit a record, it displays a Forbidden error.
The error only occurs when I change the RichText field. If I change any other field, it works normally.
If I create a record, it also works. The problem is only when I edit it.
Can someone please help me?
5 Replies

Apparently the error only occurs when the RichText HTML has
"
But I still haven't been able to solve it.This is very weird. I was leaning toward fillable on the model, but if create works then that’s not the issue. Can you share the code of your form and your model?
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Question extends Model
{
protected $fillable = ['question', 'type', 'options', 'min', 'max', 'content', 'text', 'order', 'prompt'];
protected $casts = [
'options' => 'array',
'content' => 'string',
];
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Question extends Model
{
protected $fillable = ['question', 'type', 'options', 'min', 'max', 'content', 'text', 'order', 'prompt'];
protected $casts = [
'options' => 'array',
'content' => 'string',
];
}
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\QuestionResource\Pages;
use App\Filament\Resources\QuestionResource\RelationManagers;
use App\Models\Question;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Forms\Components\TagsInput;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use App\Enums\QuestionFieldEnum;
use Filament\Tables\Columns\ToggleColumn;
class QuestionResource extends Resource
{
protected static ?string $model = Question::class;
protected static ?string $navigationIcon = 'heroicon-o-question-mark-circle';
protected static ?string $navigationLabel = 'Questões';
public static ?string $label = 'Questões';
protected static ?string $recordTitleAttribute = 'question';
public static function getGloballySearchableAttributes(): array
{
return ['question', 'type', 'text', 'content'];
}
public static function getNavigationBadge(): ?string
{
return static::getModel()::count();
}
public static function form(Form $form): Form
{
return $form
->columns(1)
->schema([
Forms\Components\TextInput::make('question')
->label('Questão')
->required()
->maxLength(255),
Forms\Components\Textarea::make('text')
->label('Texto'),
Forms\Components\Select::make('type')
->label('Tipo')
->options(collect(QuestionFieldEnum::cases())->mapWithKeys(fn($case) => [$case->value => $case->getLabel()]))
->native(false)
->searchable()
->reactive()
->required()
->default('text_input'),
Forms\Components\TagsInput::make('options')
->visible(fn(callable $get) => $get('type') === 'select')
->required(fn(callable $get) => $get('type') === 'select')
->label('Opções'),
Forms\Components\RichEditor::make('content')
->visible(fn(callable $get) => $get('type') === 'defined_text')
->required(fn(callable $get) => $get('type') === 'defined_text')
->label('Conteúdo'),
Forms\Components\TextInput::make('min')
->label('Mínimo')
->numeric(),
Forms\Components\TextInput::make('max')
->label('Máximo')
->numeric(),
Forms\Components\Toggle::make('prompt')
->label('Enviar para o prompt?')
->default(false),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ManageQuestions::route('/'),
];
}
}
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\QuestionResource\Pages;
use App\Filament\Resources\QuestionResource\RelationManagers;
use App\Models\Question;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Forms\Components\TagsInput;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use App\Enums\QuestionFieldEnum;
use Filament\Tables\Columns\ToggleColumn;
class QuestionResource extends Resource
{
protected static ?string $model = Question::class;
protected static ?string $navigationIcon = 'heroicon-o-question-mark-circle';
protected static ?string $navigationLabel = 'Questões';
public static ?string $label = 'Questões';
protected static ?string $recordTitleAttribute = 'question';
public static function getGloballySearchableAttributes(): array
{
return ['question', 'type', 'text', 'content'];
}
public static function getNavigationBadge(): ?string
{
return static::getModel()::count();
}
public static function form(Form $form): Form
{
return $form
->columns(1)
->schema([
Forms\Components\TextInput::make('question')
->label('Questão')
->required()
->maxLength(255),
Forms\Components\Textarea::make('text')
->label('Texto'),
Forms\Components\Select::make('type')
->label('Tipo')
->options(collect(QuestionFieldEnum::cases())->mapWithKeys(fn($case) => [$case->value => $case->getLabel()]))
->native(false)
->searchable()
->reactive()
->required()
->default('text_input'),
Forms\Components\TagsInput::make('options')
->visible(fn(callable $get) => $get('type') === 'select')
->required(fn(callable $get) => $get('type') === 'select')
->label('Opções'),
Forms\Components\RichEditor::make('content')
->visible(fn(callable $get) => $get('type') === 'defined_text')
->required(fn(callable $get) => $get('type') === 'defined_text')
->label('Conteúdo'),
Forms\Components\TextInput::make('min')
->label('Mínimo')
->numeric(),
Forms\Components\TextInput::make('max')
->label('Máximo')
->numeric(),
Forms\Components\Toggle::make('prompt')
->label('Enviar para o prompt?')
->default(false),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ManageQuestions::route('/'),
];
}
}
Hmm. Code looks fine. That’s also not a normal laravel error screen. I’m thinking the issue is deeper down like at the db level maybe.