1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Invoice Factory and Repo

This commit is contained in:
David Bomba 2019-04-04 10:17:15 +11:00
parent 2d5fc9e066
commit 931ea9634c
4 changed files with 46 additions and 11 deletions

View File

@ -11,23 +11,24 @@ class InvoiceController extends BaseController
use MakesHash;
protected $entityType = Invoice::class;
protected $entity_type = Invoice::class;
protected $entityTransformer = InvoiceTransformer::class;
protected $entity_transformer = InvoiceTransformer::class;
/**
* @var ClientRepository
*/
protected $clientRepo;
protected $invoice_repo;
/**
* ClientController constructor.
* @param ClientRepository $clientRepo
*/
public function __construct()
public function __construct(InvoiceRespository $invoice_repo)
{
parent::__construct();
$this->invoice_repo = $invoice_repo;
}

View File

@ -13,18 +13,16 @@ class Invoice extends BaseModel
'id',
];
protected $appends = ['invoice_id'];
public function getRouteKeyName()
public function company()
{
return 'invoice_id';
return $this->belongsTo(Company::class);
}
public function getInvoiceIdAttribute()
public function user()
{
return $this->encodePrimaryKey($this->id);
return $this->belongsTo(User::class);
}
public function invitations()
{
$this->morphMany(Invitation::class, 'inviteable');

View File

@ -0,0 +1,27 @@
<?php
namespace App\Repositories;
use App\Models\Invoice;
use Illuminate\Http\Request;
/**
*
*/
class InvoiceRepository extends BaseRepository
{
public function getClassName()
{
return Invoice::class;
}
public function save(Request $request, Invoice $invoice) : ?Invoice
{
$invoice->fill($request->input());
$invoice->save();
return $invoice;
}
}

View File

@ -0,0 +1,9 @@
<?php
use Faker\Generator as Faker;
$factory->define(Model::class, function (Faker $faker) {
return [
//
];
});