You cannot insert to multiple tables using a single query.
Jul 29, 2020
4
Level 18
Insert records from different tables with one query
I want to use the bennefit of factories, I'm improving the performance of my tests, today I have more the 400 tests, I need to refresh the database before each test, but also need 3 records from 3 different tables on each test (not all, but most)
I want to transform this code
$this->empresa = factory(Empresa::class)->create([
'codigoempresa' => 1
]);
$pessoa = factory(Pessoas::class)->create([
'codigoempresa' => 1,
'codigopes' => 1
]);
$this->apiUser = factory(ApiUser::class)->create([
'codigoempresa' => $this->empresa->codigoempresa,
'codigopes' => $pessoa->codigopes,
'api_token' => $this->token
]);
in just one query for performance improvement, I was thinking in DB::raw() but I don't know how to integrate that with factories
Level 104
Please or to participate in this conversation.