diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 4499e1cc09..6a0643e46c 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -126,7 +126,7 @@ class CreateTestData extends Command 'city' => $this->faker->city, 'state' => $this->faker->state, 'postal_code' => $this->faker->postcode, - 'vendorcontacts' => [[ + 'vendor_contacts' => [[ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, 'email' => $this->faker->safeEmail, diff --git a/app/Http/Controllers/BaseAPIController.php b/app/Http/Controllers/BaseAPIController.php index 8e48f3bff8..8ffc45ffcf 100644 --- a/app/Http/Controllers/BaseAPIController.php +++ b/app/Http/Controllers/BaseAPIController.php @@ -204,7 +204,7 @@ class BaseAPIController extends Controller } elseif ($include == 'clients') { $data[] = 'clients.contacts'; } elseif ($include == 'vendors') { - $data[] = 'vendors.vendorcontacts'; + $data[] = 'vendors.vendor_contacts'; } elseif ($include) { $data[] = $include; } diff --git a/app/Http/Controllers/ExpenseController.php b/app/Http/Controllers/ExpenseController.php index 3da123c2d9..d4184abf3f 100644 --- a/app/Http/Controllers/ExpenseController.php +++ b/app/Http/Controllers/ExpenseController.php @@ -74,7 +74,7 @@ class ExpenseController extends BaseController public function create(ExpenseRequest $request) { if ($request->vendor_id != 0) { - $vendor = Vendor::scope($request->vendor_id)->with('vendorcontacts')->firstOrFail(); + $vendor = Vendor::scope($request->vendor_id)->with('vendor_contacts')->firstOrFail(); } else { $vendor = null; } @@ -85,7 +85,7 @@ class ExpenseController extends BaseController 'method' => 'POST', 'url' => 'expenses', 'title' => trans('texts.new_expense'), - 'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(), + 'vendors' => Vendor::scope()->with('vendor_contacts')->orderBy('name')->get(), 'vendor' => $vendor, 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), 'clientPublicId' => $request->client_id, @@ -124,7 +124,7 @@ class ExpenseController extends BaseController 'url' => 'expenses/'.$expense->public_id, 'title' => 'Edit Expense', 'actions' => $actions, - 'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(), + 'vendors' => Vendor::scope()->with('vendor_contacts')->orderBy('name')->get(), 'vendorPublicId' => $expense->vendor ? $expense->vendor->public_id : null, 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), 'clientPublicId' => $expense->client ? $expense->client->public_id : null, diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index db74adb89c..ebaaa1f6c3 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -164,12 +164,12 @@ class ExportController extends BaseController if ($request->input(ENTITY_VENDOR)) { $data['clients'] = Vendor::scope() - ->with('user', 'vendorcontacts', 'country') + ->with('user', 'vendor_contacts', 'country') ->withArchived() ->get(); $data['vendor_contacts'] = VendorContact::scope() - ->with('user', 'vendor.contacts') + ->with('user', 'vendor.vendor_contacts') ->withTrashed() ->get(); diff --git a/app/Http/Controllers/VendorApiController.php b/app/Http/Controllers/VendorApiController.php index 2995e5c5e5..e15207934c 100644 --- a/app/Http/Controllers/VendorApiController.php +++ b/app/Http/Controllers/VendorApiController.php @@ -81,7 +81,7 @@ class VendorApiController extends BaseAPIController $vendor = $this->vendorRepo->save($request->input()); $vendor = Vendor::scope($vendor->public_id) - ->with('country', 'vendorcontacts', 'industry', 'size', 'currency') + ->with('country', 'vendor_contacts', 'industry', 'size', 'currency') ->first(); return $this->itemResponse($vendor); diff --git a/app/Http/Requests/VendorRequest.php b/app/Http/Requests/VendorRequest.php index 600678686c..a06e5ad808 100644 --- a/app/Http/Requests/VendorRequest.php +++ b/app/Http/Requests/VendorRequest.php @@ -9,8 +9,8 @@ class VendorRequest extends EntityRequest { $vendor = parent::entity(); // eager load the contacts - if ($vendor && ! count($vendor->vendorcontacts)) { - $vendor->load('vendorcontacts'); + if ($vendor && ! count($vendor->vendor_contacts)) { + $vendor->load('vendor_contacts'); } return $vendor; diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index 573a581e47..6fcd10f140 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -95,7 +95,7 @@ class Vendor extends EntityModel return $this->hasMany('App\Models\Payment'); } - public function vendorContacts() + public function vendor_contacts() { return $this->hasMany('App\Models\VendorContact'); } @@ -143,7 +143,7 @@ class Vendor extends EntityModel $contact->fill($data); $contact->is_primary = $isPrimary; - return $this->vendorContacts()->save($contact); + return $this->vendor_contacts()->save($contact); } public function getRoute() diff --git a/app/Ninja/Repositories/VendorRepository.php b/app/Ninja/Repositories/VendorRepository.php index ef5648f47d..82e1bfdd18 100644 --- a/app/Ninja/Repositories/VendorRepository.php +++ b/app/Ninja/Repositories/VendorRepository.php @@ -16,7 +16,7 @@ class VendorRepository extends BaseRepository public function all() { return Vendor::scope() - ->with('user', 'vendorcontacts', 'country') + ->with('user', 'vendor_contacts', 'country') ->withTrashed() ->where('is_deleted', '=', false) ->get(); @@ -71,7 +71,7 @@ class VendorRepository extends BaseRepository } elseif (!$publicId || $publicId == '-1') { $vendor = Vendor::createNew(); } else { - $vendor = Vendor::scope($publicId)->with('vendorcontacts')->firstOrFail(); + $vendor = Vendor::scope($publicId)->with('vendor_contacts')->firstOrFail(); \Log::warning('Entity not set in vendor repo save'); } @@ -79,7 +79,7 @@ class VendorRepository extends BaseRepository $vendor->save(); $first = true; - $vendorcontacts = isset($data['vendorcontact']) ? [$data['vendorcontact']] : $data['vendorcontacts']; + $vendorcontacts = isset($data['vendor_contact']) ? [$data['vendor_contact']] : $data['vendor_contacts']; foreach ($vendorcontacts as $vendorcontact) { $vendorcontact = $vendor->addVendorContact($vendorcontact, $first); diff --git a/app/Ninja/Transformers/VendorTransformer.php b/app/Ninja/Transformers/VendorTransformer.php index 2af79422fd..df8dc5ea34 100644 --- a/app/Ninja/Transformers/VendorTransformer.php +++ b/app/Ninja/Transformers/VendorTransformer.php @@ -36,7 +36,7 @@ class VendorTransformer extends EntityTransformer */ protected $defaultIncludes = [ - 'vendorContacts', + 'vendor_contacts', ]; protected $availableIncludes = [ @@ -47,7 +47,7 @@ class VendorTransformer extends EntityTransformer public function includeVendorContacts(Vendor $vendor) { $transformer = new VendorContactTransformer($this->account, $this->serializer); - return $this->includeCollection($vendor->vendorContacts, $transformer, ENTITY_CONTACT); + return $this->includeCollection($vendor->vendor_contacts, $transformer, ENTITY_CONTACT); } public function includeInvoices(Vendor $vendor) diff --git a/resources/views/vendors/edit.blade.php b/resources/views/vendors/edit.blade.php index 5a61287b2b..82a6192815 100644 --- a/resources/views/vendors/edit.blade.php +++ b/resources/views/vendors/edit.blade.php @@ -7,8 +7,8 @@ @section('content') -@if ($errors->first('vendorcontacts')) -
{{ trans($errors->first('vendorcontacts')) }}
+@if ($errors->first('vendor_contacts')) +
{{ trans($errors->first('vendor_contacts')) }}
@endif
@@ -73,26 +73,26 @@
-
{!! Former::hidden('public_id')->data_bind("value: public_id, valueUpdate: 'afterkeydown', - attr: {name: 'vendorcontacts[' + \$index() + '][public_id]'}") !!} + attr: {name: 'vendor_contacts[' + \$index() + '][public_id]'}") !!} {!! Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown', - attr: {name: 'vendorcontacts[' + \$index() + '][first_name]'}") !!} + attr: {name: 'vendor_contacts[' + \$index() + '][first_name]'}") !!} {!! Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown', - attr: {name: 'vendorcontacts[' + \$index() + '][last_name]'}") !!} + attr: {name: 'vendor_contacts[' + \$index() + '][last_name]'}") !!} {!! Former::text('email')->data_bind("value: email, valueUpdate: 'afterkeydown', - attr: {name: 'vendorcontacts[' + \$index() + '][email]', id:'email'+\$index()}") !!} + attr: {name: 'vendor_contacts[' + \$index() + '][email]', id:'email'+\$index()}") !!} {!! Former::text('phone')->data_bind("value: phone, valueUpdate: 'afterkeydown', - attr: {name: 'vendorcontacts[' + \$index() + '][phone]'}") !!} + attr: {name: 'vendor_contacts[' + \$index() + '][phone]'}") !!}
- + {!! link_to('#', trans('texts.remove_contact').' -', array('data-bind'=>'click: $parent.removeContact')) !!} - + {!! link_to('#', trans('texts.add_contact').' +', array('onclick'=>'return addContact()')) !!}
@@ -186,10 +186,10 @@ function VendorModel(data) { var self = this; - self.vendorcontacts = ko.observableArray(); + self.vendor_contacts = ko.observableArray(); self.mapping = { - 'vendorcontacts': { + 'vendor_contacts': { create: function(options) { return new VendorContactModel(options.data); } @@ -199,12 +199,12 @@ if (data) { ko.mapping.fromJS(data, self.mapping, this); } else { - self.vendorcontacts.push(new VendorContactModel()); + self.vendor_contacts.push(new VendorContactModel()); } self.placeholderName = ko.computed(function() { - if (self.vendorcontacts().length == 0) return ''; - var contact = self.vendorcontacts()[0]; + if (self.vendor_contacts().length == 0) return ''; + var contact = self.vendor_contacts()[0]; if (contact.first_name() || contact.last_name()) { return contact.first_name() + ' ' + contact.last_name(); } else { @@ -226,12 +226,12 @@ ko.applyBindings(model); function addContact() { - model.vendorcontacts.push(new VendorContactModel()); + model.vendor_contacts.push(new VendorContactModel()); return false; } model.removeContact = function() { - model.vendorcontacts.remove(this); + model.vendor_contacts.remove(this); } diff --git a/resources/views/vendors/show.blade.php b/resources/views/vendors/show.blade.php index 62037179e7..37572ee4c5 100644 --- a/resources/views/vendors/show.blade.php +++ b/resources/views/vendors/show.blade.php @@ -109,7 +109,7 @@

{{ trans('texts.contacts') }}

- @foreach ($vendor->vendorcontacts as $contact) + @foreach ($vendor->vendor_contacts as $contact) @if ($contact->first_name || $contact->last_name) {{ $contact->first_name.' '.$contact->last_name }}
@endif diff --git a/tests/acceptance/APICest.php b/tests/acceptance/APICest.php index ee36c6265e..41e9225396 100644 --- a/tests/acceptance/APICest.php +++ b/tests/acceptance/APICest.php @@ -78,7 +78,7 @@ class APICest $data = new stdClass; $data->name = $this->faker->word; - $data->vendorcontacts = []; + $data->vendor_contacts = []; $this->createEntity('vendor', $data); $this->listEntities('vendor');