I'm new to Laravel and I'm trying to insert n models from n appended html inputs Does Laravel's `Eloquent have a better way than this ?
public function store(Request $request, Domain $domain, Server $server)
{
$new_domain = $domain->create($request->all());
$server->fill($request->only(['srv_hostname','srv_ip','srv_port']));
$servers = array();
$total = count($server['attributes']['srv_hostname']);
for ($i=0;$i<$total;$i++){
$p = new Server;
$p->domain()->associate($new_domain);
$p->srv_hostname = $server['attributes']['srv_hostname'][$i];
$p->srv_ip = $server['attributes']['srv_ip'][$i];
$p->srv_port = $server['attributes']['srv_port'][$i];
$p->save();
}
return redirect()->route('domains.index');
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1OtIkWa
via IFTTT
Aucun commentaire:
Enregistrer un commentaire