info('Setting up Oasis environment'); $this->create_demo_content(); $this->info('Dispatching jobs...'); $this->call('queue:work', [ '--stop-when-empty' => true, ]); $this->info('Everything is done, congratulations! 🥳🥳🥳'); } public function create_demo_content() { $user = User::whereEmail('howdy@hi5ve.digital') ->first(); $clients = Client::factory(Client::class) ->count(6) ->create(['user_id' => $user->id]); $regular_invoices = Invoice::factory(Invoice::class) ->state(new Sequence( ['client_id' => $clients[0]->id], ['client_id' => $clients[1]->id], ['client_id' => $clients[2]->id], ['client_id' => $clients[3]->id], ['client_id' => $clients[4]->id], ['client_id' => $clients[5]->id], ))->count(2) ->create([ 'user_id' => $user->id, 'invoice_type' => 'regular-invoice' ]); $advance_invoices = Invoice::factory(Invoice::class) ->count(2) ->state(new Sequence( ['client_id' => $clients[0]->id], ['client_id' => $clients[1]->id], ['client_id' => $clients[2]->id], ['client_id' => $clients[3]->id], ['client_id' => $clients[4]->id], ['client_id' => $clients[5]->id], ))->create([ 'user_id' => $user->id, 'invoice_type' => 'advance-invoice', 'discount_type' => null, ]); // Generate PDF collect([$regular_invoices, $advance_invoices]) ->collapse() ->each(function ($invoice) use ($user) { $this->info("Generating invoice id: $invoice->id"); \PDF::loadView('oasis.invoices.invoice', [ 'invoice' => Invoice::find($invoice->id), 'user' => $user, ]) ->setPaper('a4') ->setOrientation('portrait') ->save( storage_path("app/files/{$invoice->user_id}/invoice-{$invoice->id}.pdf") ); }); } }