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:
Full solution is ``` Repeater::make('contents') ->relationship('contents', modifyQueryUsing: fn ($query) => $query->where('language', 'en')) ->schema([ RichEditor::make('description') ])...
Jump to solution
38 Replies
toeknee
toeknee4mo ago
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); }
mile4841
mile4841OP4mo ago
No it is in resource, do you have idea how i can add it there
toeknee
toeknee4mo ago
if it's in a resource and you are editing it'll be filled from the record
mile4841
mile4841OP4mo ago
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; })
toeknee
toeknee4mo ago
So add it as a relationship
mile4841
mile4841OP4mo ago
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?
toeknee
toeknee4mo ago
Are you a laravel developer? If you add a relationship to the table it references then you can render it with myrelationship.description
mile4841
mile4841OP4mo ago
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')
toeknee
toeknee4mo ago
->default('my value') for creation only
mile4841
mile4841OP4mo ago
on mine edit resource still nothing
No description
toeknee
toeknee4mo ago
Edit will fill from it's values if you are editing the record should have a value hence why I said for creation only
Dennis Koch
Dennis Koch4mo ago
@mile4841 Can you please read our #✅┊rules for proper code formatting.
mile4841
mile4841OP4mo ago
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
Dennis Koch
Dennis Koch4mo ago
RichText doesn't support relations. You can use a Layout field as a wrapper. What kind of relation is this?
mile4841
mile4841OP4mo ago
hasMany
Dennis Koch
Dennis Koch4mo ago
So how are many records related to one RichEditor? Can you explain what you are trying to do?
mile4841
mile4841OP4mo ago
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
Dennis Koch
Dennis Koch4mo ago
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?`
mile4841
mile4841OP4mo ago
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
Dennis Koch
Dennis Koch4mo ago
Why aren't you just using a Relation Manager for companies_contents?
mile4841
mile4841OP4mo ago
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
Dennis Koch
Dennis Koch4mo ago
But when a company has 50 contents how would you solve that? You could also do a Repeater :
Repeater::make('contents')
->relationship('contents')
->schema([
RichEditor::make('description')
])
Repeater::make('contents')
->relationship('contents')
->schema([
RichEditor::make('description')
])
mile4841
mile4841OP4mo ago
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
Dennis Koch
Dennis Koch4mo ago
will tell take me data for the en
I don't know how your data looks like? How do you get only en?
mile4841
mile4841OP4mo ago
No description
Dennis Koch
Dennis Koch4mo ago
I think this could work: ->relationship('contents', query: fn ($query) => $query->where('languages', 'en'))
mile4841
mile4841OP4mo ago
Repeater::make('contents')
->relationship('contents',
modifyQueryUsing: fn ($query) =>$query->where('language', 'en'))
->schema([
RichEditor::make('description')
])


Repeater::make('contents')
->relationship('contents',
modifyQueryUsing: fn ($query) =>$query->where('language', 'en'))
->schema([
RichEditor::make('description')
])


Dennis Koch
Dennis Koch4mo ago
Does that work for you?
mile4841
mile4841OP4mo ago
this works but the problem is that this repeater add
No description
Dennis Koch
Dennis Koch4mo ago
There should be options to disabled both I think
mile4841
mile4841OP4mo ago
okay great thanks
Solution
mile4841
mile48414mo ago
Full solution is
Repeater::make('contents')
->relationship('contents', modifyQueryUsing: fn ($query) => $query->where('language', 'en'))
->schema([
RichEditor::make('description')
])
->addable(false)
->deletable(false)

Repeater::make('contents')
->relationship('contents', modifyQueryUsing: fn ($query) => $query->where('language', 'en'))
->schema([
RichEditor::make('description')
])
->addable(false)
->deletable(false)

mile4841
mile4841OP4mo ago
Thanks man @Dennis Koch
Dennis Koch
Dennis Koch4mo ago
You're welcome
SuperUserDo
SuperUserDo4mo ago
Hi guys, just wondered what is best solution to implement with BelongsToMany() relationship? 🙂
Dennis Koch
Dennis Koch4mo ago
To implement what? Please open a new thread an provide some info
SuperUserDo
SuperUserDo4mo ago
Sure thing, i will do that later in the evning! 🙂
jey
jey4mo ago
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
Want results from more Discord servers?
Add your server