/** @test */
 function it_has_a_customer()
 {
     $customer = new Customer(['name' => 'Test Customer']);
     $customer->save();
     $invoice = new Invoice(['title' => 'Test Invoice']);
     $customer->addInvoice($invoice);
     $this->assertEquals($customer->id, $invoice->customer_id);
 }
 /** @test */
 function it_has_multiple_invoices()
 {
     $customer = new Customer(['name' => 'Test Customer']);
     $customer->save();
     $invoice_1 = new Invoice(['title' => 'Invoice #1']);
     $invoice_2 = new Invoice(['title' => 'Invoice #2']);
     $invoice_3 = new Invoice(['title' => 'Invoice #3']);
     $customer->addInvoice($invoice_1);
     $customer->addInvoice($invoice_2);
     $customer->addInvoice($invoice_3);
     $this->assertCount(3, $customer->invoices);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param StoreRequest $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(StoreRequest $request)
 {
     $customer = Customer::findOrFail($request->customer_id);
     $invoice = new Invoice($request->all());
     $invoice->customer()->associate($customer);
     $invoice->save();
     event(new InvoiceHasBeenCreated($this->transformer->transform($invoice)));
     return $this->respondCreated('The invoice has been created');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  \VividFinance\Customer $customer
  *
  * @return \Illuminate\Http\Response
  * @throws \Exception
  */
 public function destroy(Customer $customer)
 {
     $customer->delete();
     return $this->respondWithSuccess('The customer has been deleted');
 }