1
Good afternoon!
I created an application in Laravel where I need to save the data of a particular product, it has a relationship one to n. I’d like to know the best way to do that. I’m trying the way below but it’s not working, it creates the records of the photos and position but does not pass the captured in $request.
View:
<input type='text' name='photos[0][url]'>
<input type='text' placeholder='Posição de exibição' name='photos[0][position]'>
<br>
<input type='text' name='photos[1][url]'>
<input type='text' placeholder='Posição de exibição' name='photos[1][position]'>
Controller:
$product = Product::create($request->all());
$photos = $request->get('photos');
$product->photos()->createMany($photos);
Model:
public function photos() {
return $this->hasMany('Grafica\Model\ProductPhoto');
}
Thank you for the answer. I did this but it didn’t solve the problem, when I give the createMany, the photos data is not saved in it..
– CGachido