From 401cb602140626dc7a7f9440b708839bec022152 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 1 Nov 2017 20:31:08 +0800 Subject: [PATCH] Add website and is_active column in vendors table --- app/Entities/Partners/Vendor.php | 2 +- app/Http/Controllers/Partners/VendorsController.php | 3 +++ .../2017_11_01_185745_create_vendors_table.php | 2 ++ resources/views/vendors/forms.blade.php | 3 +++ tests/Feature/ManageVendorsTest.php | 20 ++++++++++++++------ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/Entities/Partners/Vendor.php b/app/Entities/Partners/Vendor.php index 2a6b1cc..db719b5 100644 --- a/app/Entities/Partners/Vendor.php +++ b/app/Entities/Partners/Vendor.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class Vendor extends Model { - protected $fillable = ['name', 'description', 'owner_id']; + protected $fillable = ['name', 'description', 'website', 'owner_id', 'is_active']; public function owner() { diff --git a/app/Http/Controllers/Partners/VendorsController.php b/app/Http/Controllers/Partners/VendorsController.php index 7c799c9..1776855 100644 --- a/app/Http/Controllers/Partners/VendorsController.php +++ b/app/Http/Controllers/Partners/VendorsController.php @@ -38,6 +38,7 @@ class VendorsController extends Controller $newVendorData = $this->validate($request, [ 'name' => 'required|max:60', 'description' => 'nullable|max:255', + 'website' => 'nullable|url|max:255', ]); $newVendorData['owner_id'] = auth()->user()->agency->id; @@ -60,6 +61,8 @@ class VendorsController extends Controller $vendorData = $this->validate($request, [ 'name' => 'required|max:60', 'description' => 'nullable|max:255', + 'website' => 'nullable|url|max:255', + 'is_active' => 'required|boolean', ]); $routeParam = request()->only('page', 'q'); diff --git a/database/migrations/2017_11_01_185745_create_vendors_table.php b/database/migrations/2017_11_01_185745_create_vendors_table.php index f2d6371..38f83d1 100644 --- a/database/migrations/2017_11_01_185745_create_vendors_table.php +++ b/database/migrations/2017_11_01_185745_create_vendors_table.php @@ -18,6 +18,8 @@ class CreateVendorsTable extends Migration $table->string('name', 60); $table->string('description')->nullable(); $table->unsignedInteger('owner_id'); + $table->string('website')->nullable(); + $table->boolean('is_active')->default(1); $table->timestamps(); }); } diff --git a/resources/views/vendors/forms.blade.php b/resources/views/vendors/forms.blade.php index cc49fa4..b395d81 100644 --- a/resources/views/vendors/forms.blade.php +++ b/resources/views/vendors/forms.blade.php @@ -2,6 +2,7 @@ {!! Form::open(['route' => 'vendors.store']) !!} {!! FormField::text('name', ['required' => true]) !!} {!! FormField::textarea('description') !!} + {!! FormField::text('website') !!} {!! Form::submit(trans('vendor.create'), ['class' => 'btn btn-success']) !!} {{ link_to_route('vendors.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {!! Form::close() !!} @@ -10,6 +11,8 @@ {!! Form::model($editableVendor, ['route' => ['vendors.update', $editableVendor->id],'method' => 'patch']) !!} {!! FormField::text('name', ['required' => true]) !!} {!! FormField::textarea('description') !!} + {!! FormField::text('website') !!} + {!! FormField::radios('is_active', ['Non Aktif', 'Aktif']) !!} @if (request('q')) {{ Form::hidden('q', request('q')) }} @endif diff --git a/tests/Feature/ManageVendorsTest.php b/tests/Feature/ManageVendorsTest.php index d72a65a..2ba31c2 100644 --- a/tests/Feature/ManageVendorsTest.php +++ b/tests/Feature/ManageVendorsTest.php @@ -31,9 +31,11 @@ class ManageVendorsTest extends TestCase $this->click(trans('vendor.create')); $this->seePageIs(route('vendors.index', ['action' => 'create'])); - $this->type('Vendor 1 name', 'name'); - $this->type('Vendor 1 description', 'description'); - $this->press(trans('vendor.create')); + $this->submitForm(trans('vendor.create'), [ + 'name' => 'Vendor 1 name', + 'description' => 'Vendor 1 description', + 'website' => 'https://example.com', + ]); $this->see(trans('vendor.created')); $this->seePageIs(route('vendors.index')); @@ -41,6 +43,7 @@ class ManageVendorsTest extends TestCase $this->seeInDatabase('vendors', [ 'name' => 'Vendor 1 name', 'description' => 'Vendor 1 description', + 'website' => 'https://example.com', ]); } @@ -54,9 +57,12 @@ class ManageVendorsTest extends TestCase $this->click('edit-vendor-'.$vendor->id); $this->seePageIs(route('vendors.index', ['action' => 'edit', 'id' => $vendor->id, 'q' => '123'])); - $this->type('Vendor 1 name', 'name'); - $this->type('Vendor 1 description', 'description'); - $this->press(trans('vendor.update')); + $this->submitForm(trans('vendor.update'), [ + 'name' => 'Vendor 1 name', + 'description' => 'Vendor 1 description', + 'website' => 'https://example.com', + 'is_active' => 0, + ]); $this->see(trans('vendor.updated')); $this->seePageIs(route('vendors.index', ['q' => '123'])); @@ -64,6 +70,8 @@ class ManageVendorsTest extends TestCase $this->seeInDatabase('vendors', [ 'name' => 'Vendor 1 name', 'description' => 'Vendor 1 description', + 'website' => 'https://example.com', + 'is_active' => 0, ]); }