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
Emir Çelik
Emir ÇelikOP9mo ago
yep but i didint 😦
Patrick
Patrick9mo ago
Can u share code ? Is there a relationship between product and product_info ?
Emir Çelik
Emir ÇelikOP9mo ago
Product.php
public function milyem()
{
return $this->hasOne(ProductHasMilyem::class, 'product_id');
}

public function milyem()
{
return $this->hasOne(ProductHasMilyem::class, 'product_id');
}

ProductHasMilyem.php
public function product()
{
return $this->belongsTo(Product::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
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
Patrick
Patrick9mo ago
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; } // ... }
Emir Çelik
Emir ÇelikOP9mo ago
thanks i do try
Want results from more Discord servers?
Add your server