Browse Source

Add website field on customers table

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
43dd471ee8
  1. 2
      app/Entities/Partners/Customer.php
  2. 10
      app/Http/Controllers/Partners/CustomersController.php
  3. 1
      database/migrations/2017_10_26_134455_create_customers_table.php
  4. 1
      resources/views/customers/create.blade.php
  5. 1
      resources/views/customers/edit.blade.php
  6. 10
      tests/Feature/Partners/ManageCustomersTest.php

2
app/Entities/Partners/Customer.php

@ -9,7 +9,7 @@ class Customer extends Model
{
use OwnedByAgency;
protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'notes', 'is_active', 'owner_id'];
protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'website', 'notes', 'is_active', 'owner_id'];
public function owner()
{

10
app/Http/Controllers/Partners/CustomersController.php

@ -15,19 +15,13 @@ class CustomersController extends Controller
*/
public function index()
{
$editableCustomer = null;
$customers = Customer::where(function ($query) {
$query->where('name', 'like', '%'.request('q').'%');
})
->withCount('projects')
->paginate(25);
if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) {
$editableCustomer = Customer::find(request('id'));
}
return view('customers.index', compact('customers', 'editableCustomer'));
return view('customers.index', compact('customers'));
}
/**
@ -54,6 +48,7 @@ class CustomersController extends Controller
'phone' => 'nullable|max:255',
'pic' => 'nullable|max:255',
'address' => 'nullable|max:255',
'website' => 'nullable|url|max:255',
'notes' => 'nullable|max:255',
]);
@ -103,6 +98,7 @@ class CustomersController extends Controller
'phone' => 'nullable|max:255',
'pic' => 'nullable|max:255',
'address' => 'nullable|max:255',
'website' => 'nullable|url|max:255',
'notes' => 'nullable|max:255',
'is_active' => 'required|boolean',
]);

1
database/migrations/2017_10_26_134455_create_customers_table.php

@ -20,6 +20,7 @@ class CreateCustomersTable extends Migration
$table->string('phone')->nullable();
$table->string('pic')->nullable();
$table->string('address')->nullable();
$table->string('website')->nullable();
$table->string('notes')->nullable();
$table->boolean('is_active')->default(1);
$table->unsignedInteger('owner_id');

1
resources/views/customers/create.blade.php

@ -28,6 +28,7 @@
<div class="col-xs-7">{!! FormField::email('email') !!}</div>
<div class="col-xs-5">{!! FormField::text('phone') !!}</div>
</div>
{!! FormField::text('website') !!}
{!! FormField::textarea('address') !!}
</div>
</div>

1
resources/views/customers/edit.blade.php

@ -33,6 +33,7 @@
<div class="col-xs-7">{!! FormField::email('email') !!}</div>
<div class="col-xs-5">{!! FormField::text('phone') !!}</div>
</div>
{!! FormField::text('website') !!}
{!! FormField::textarea('address') !!}
</div>
</div>

10
tests/Feature/Partners/ManageCustomersTest.php

@ -13,7 +13,7 @@ class ManageCustomersTest extends TestCase
/** @test */
public function user_can_see_customer_list_in_customer_index_page()
{
$user = $this->adminUserSigningIn();
$user = $this->adminUserSigningIn();
$customer1 = factory(Customer::class)->create(['owner_id' => $user->agency->id]);
$customer2 = factory(Customer::class)->create(['owner_id' => $user->agency->id]);
@ -37,6 +37,7 @@ class ManageCustomersTest extends TestCase
'phone' => '081234567890',
'pic' => 'Nama PIC Customer',
'address' => 'Alamat customer 1',
'website' => 'https://example.com',
'notes' => '',
]);
@ -48,6 +49,7 @@ class ManageCustomersTest extends TestCase
'phone' => '081234567890',
'pic' => 'Nama PIC Customer',
'address' => 'Alamat customer 1',
'website' => 'https://example.com',
'notes' => null,
'owner_id' => $user->agency->id,
]);
@ -56,7 +58,7 @@ class ManageCustomersTest extends TestCase
/** @test */
public function user_can_edit_a_customer()
{
$user = $this->adminUserSigningIn();
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create(['owner_id' => $user->agency->id, 'name' => 'Testing 123']);
$this->visit(route('customers.show', [$customer->id]));
@ -69,6 +71,7 @@ class ManageCustomersTest extends TestCase
'phone' => '081234567890',
'pic' => 'Nama PIC Customer',
'address' => 'Alamat customer 1',
'website' => 'https://example.com',
'notes' => '',
'is_active' => 0,
]);
@ -81,6 +84,7 @@ class ManageCustomersTest extends TestCase
'phone' => '081234567890',
'pic' => 'Nama PIC Customer',
'address' => 'Alamat customer 1',
'website' => 'https://example.com',
'notes' => null,
'is_active' => 0,
]);
@ -89,7 +93,7 @@ class ManageCustomersTest extends TestCase
/** @test */
public function user_can_delete_a_customer()
{
$user = $this->adminUserSigningIn();
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]);
$this->visit(route('customers.edit', [$customer->id]));

Loading…
Cancel
Save