Hi,
I’m searching a way to render items in a Relation widget rendered on my parent create page,
i have two different model with a relation,
- Template
hasMany TemplateProducts - Booking
hasMany BookingProducts
On my Booking index page, I can choose to create a Booking based on a Template Model, so that when I get to the create page, the BookingProducts relationship will already be pre-filled with TemplateProducts.
I have tried to do something like this with the formExtendModel
function, but the relation widget is always empty. Someone could help me to understand where i’m wrong please ?
public function formExtendModel($model)
{
if (Session::has('templateId') && !$model->exists) {
$templateId= Session::get('templateId');
$template= Template::find($templateId);
foreach ($template->products as $product) {
$BookingProduct = new BookingProducts;
$BookingProduct->product_id = $product->id;
$BookingProduct->declinaison_id = $product->declinaison_id;
$BookingProduct->dossier_id = null;
$BookingProduct->quantity = $product->quantity;
$BookingProduct->price_vente_ht = $product->price_vente_ht;
$BookingProduct->categorie_id = $product->categorie_id;
$BookingProduct->piece_id = $product->piece_id;
$BookingProduct ->save();
$model->products()->add($BookingProduct);
}
Session::forget('packId');
}
return $model;
}
best,
Lucas