@goatshark First question - you've setup Node hasMany Port relation only to make it easy for you, is that right? Meaning, there is no real connection between the two?
If that's the case, then get rid of it, since you can easily achieve what you wanted:
// Node model
public function ports()
{
return $this->hasManyThrough(Port::class, Module::class);
}
then you can get the ports of a node:
$node->ports; // collection of Port models related through Modules
So all you need to create a new one is:
public function store(CreatePortRequest $request, $node, $module)
{
$port = new Port($request->all());
$module->ports()->save($port);
return redirect()->route('nodes.modules.ports.index', ['node' => $node->id, 'module' => $module->id]);
}
I assume you've bound $module to the route, so it is a Model already. That said, you don't need this part:
Module::find($module->id)...
because it has been already fetched for you.