Relations..
Hello, I have a product resource, there is a rich editor in it, and the information entered there should be created in the product_info table after the product is created. but I couldn't do this. First, I need to create the product, get its id value, and then record the product_id and the value in the rich editor in product_info.
6 Replies
yep but i didint 😦
Can u share code ? Is there a relationship between product and product_info ?
Product.php
ProductHasMilyem.php
I mentioned product info as an example so that we don't get confused. My real fiction is like this
https://codeshare.io/mPORpw
these are my codes
Perhaps sth like:
class ProductResource extends Resource
{
// ...
protected static function form(Form $form): Form
{
return $form
->schema([
RichEditor::make('info')
->label('Product Info')
->required()
->reactive()
->afterStateUpdated(fn ($state, callable $set) => $set('productInfo.info', $state)), //<- info equals the field where you want to save the information
]);
}
// ...
Then in your CreateProduct / EditProduct page you could use sth like:
public static function mutateFormDataBeforeSave(array $data): array
{
if (isset($data['info'])) {
$data['productInfo']['info'] = $data['info'];
unset($data['info']);
}
return $data;
}
public static function mutateFormDataBeforeFill(array $data): array
{
if (isset($data['productInfo']['info'])) {
$data['info'] = $data['productInfo']['info'];
}
return $data;
}
// ...
}
thanks i do try