This sounds like an electrical actuator or sensor at fault .Usually when you can cycle the ignition key on / off and then restart the engine and the fault is gone temporarily this indicates that this is an electrical component causing this issue.
This could be a wiring issue as things tend to expand when hot and its possible a poor or partial electrical connection is being pushed apart on one of the major sensors so check the connection plug and wiring to the following;
Crank position sensor
Cam position sensor
Throttle pedal position sensor
unplug each in turn and use some switch / contact cleaner spray on the pins to ensure its all grease / dirt free
Also worth checking the connections to the fuel pump for the same reason - unplug each in turn and give them a good squirt of switch / contact cleaner - Not WD40
and also unplug and inspect the main power relays and fuses for signs of overheating or corroded terminals - so the ones for the ECU and the fuel pump
And also unplug the wiring loom connections in the engine bay one at time and inspect for corroded or recessed pins.
Also check that the alternator is actually charging the battery in the car by taking a battery voltage reading with the engine off then another with the engine running. The 2nd reading should be higher than the 1st and climbing steadily. And also check that the alternator is secure to the engine as this provides the ground for the charging circuit and make sure that the engine / gearbox earth strap is secure and the contacts are clean and bright.
if the alternator appears not to be working - take it to a electrical specialist and ask them to test it as sometimes you can replace just the diode pack and this will repair the alternator without requiring replacement
And one last thing is – how old is the battery? – As even good quality ones need replacing every 5 years and faulty battery just won’t hold a charge