How to set value inside of richEditor
Hi i would like to insert a value in richeditor from mine Model, how i can do it for example i want this
RichEditor::make('description')
->value(function(Model $record){
return $record->description;
}),
Solution:Jump to solution
Full solution is ``` Repeater::make('contents')
->relationship('contents', modifyQueryUsing: fn ($query) => $query->where('language', 'en'))
->schema([
RichEditor::make('description')
])...
38 Replies
Is this. in a custom form not a resource
if so on the $form do $form->model($this->record); and in
function mount($id) {
$this->record = MyModel::Find($id);
}
No it is in resource, do you have idea how i can add it there
if it's in a resource and you are editing it'll be filled from the record
the field is from another table in DB, i somehow needs to fill that field like i would do it here Tables\Columns\ImageColumn::make('image')
->label('Image')
->getStateUsing(function (Record $record): string {
return $record->otherTable;
})
So add it as a relationship
You mean like these RichEditor::make('description')
->relationship('contents'), than these is not working, or do you mean i have to make a relation manager?
Are you a laravel developer? If you add a relationship to the table it references then you can render it with myrelationship.description
Okay, i did not ask a good question. How do i insert some value into rich editor? what to add here so i can have some value inside RichEditor::make('description')
->default('my value')
for creation only
on mine edit resource still nothing
Edit will fill from it's values
if you are editing the record should have a value
hence why I said for creation only
@mile4841 Can you please read our #✅┊rules for proper code formatting.
Okay., thanks, what then i have to do so it fill mine filed if mine relation is contents and column name is description, what i have to write here in RichEditor::make(here what i should write)
Sorry, i will see
RichText doesn't support relations. You can use a Layout field as a wrapper. What kind of relation is this?
hasMany
So how are many records related to one RichEditor?
Can you explain what you are trying to do?
i am trying when i click a link edit, in mine edit resource where i have richEditor i want inside a richeditor to have value from table 'mine_contents' to take value from column description
So you have a Resource. And you click "Edit". Then there should be a Editor with the data prefilled from a HasMany relation? But which data does it use if there are many?`
I have a table 'companies' and table companies_contents inside companies_contents i have a column description i want to make a crud from companies
i just make an example of what i have and what is mine problem
Did i explain well mine problem
Why aren't you just using a Relation Manager for
companies_contents
?i was thinking of that, but i just think it is to much for such a simple problem
Thanks for help i will go with relation manager
But when a company has 50 contents how would you solve that?
You could also do a
Repeater
:
it is multi languages website, this works but it show all contents from different languages, is there an option that do the same just that will tell take me data for the en
will tell take me data for the enI don't know how your data looks like? How do you get only en?
I think this could work:
->relationship('contents', query: fn ($query) => $query->where('languages', 'en'))
Does that work for you?
this works but the problem is that this repeater add
There should be options to disabled both I think
okay great thanks
Solution
Full solution is
Thanks man @Dennis Koch
You're welcome
Hi guys, just wondered what is best solution to implement with BelongsToMany() relationship? 🙂
To implement what? Please open a new thread an provide some info
Sure thing, i will do that later in the evning! 🙂
pard me for asking , but why not use spatie translatable package for translations instead of creating separate tables for other data ? it's not a crime to use json and make a table with many columns imo