Browse Source

Add website and is_active column in vendors table

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
401cb60214
  1. 2
      app/Entities/Partners/Vendor.php
  2. 3
      app/Http/Controllers/Partners/VendorsController.php
  3. 2
      database/migrations/2017_11_01_185745_create_vendors_table.php
  4. 3
      resources/views/vendors/forms.blade.php
  5. 20
      tests/Feature/ManageVendorsTest.php

2
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()
{

3
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');

2
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();
});
}

3
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

20
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,
]);
}

Loading…
Cancel
Save