diff --git a/app/Entities/Partners/Vendor.php b/app/Entities/Partners/Vendor.php new file mode 100644 index 0000000..0d4f51d --- /dev/null +++ b/app/Entities/Partners/Vendor.php @@ -0,0 +1,10 @@ +where('name', 'like', '%'.request('q').'%'); + })->paginate(25); + + if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { + $editableVendor = Vendor::find(request('id')); + } + + return view('vendors.index', compact('vendors', 'editableVendor')); + } + + /** + * Store a newly created vendor in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + $newVendorData = $this->validate($request, [ + 'name' => 'required|max:60', + 'email' => 'nullable|email|unique:vendors,email', + 'phone' => 'nullable', + 'notes' => 'nullable|max:255', + ]); + + Vendor::create($newVendorData); + + flash(trans('vendor.created'), 'success'); + + return redirect()->route('vendors.index'); + } + + /** + * Update the specified vendor in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\Entities\Partners\Vendor $vendor + * @return \Illuminate\Http\Response + */ + public function update(Request $request, Vendor $vendor) + { + $vendorData = $this->validate($request, [ + 'name' => 'required|max:60', + 'email' => 'nullable|email|unique:vendors,email,'.$vendor->id, + 'phone' => 'nullable', + 'notes' => 'nullable|max:255', + 'is_active' => 'required|boolean', + ]); + + $routeParam = request()->only('page', 'q'); + + $vendor = $vendor->update($vendorData); + + flash(trans('vendor.updated'), 'success'); + return redirect()->route('vendors.index', $routeParam); + } + + /** + * Remove the specified vendor from storage. + * + * @param \App\Entities\Partners\Vendor $vendor + * @return \Illuminate\Http\Response + */ + public function destroy(Vendor $vendor) + { + // TODO: user cannot delete vendor that has been used in other table + $this->validate(request(), [ + 'vendor_id' => 'required', + ]); + + $routeParam = request()->only('page', 'q'); + + if (request('vendor_id') == $vendor->id && $vendor->delete()) { + flash(trans('vendor.deleted'), 'warning'); + return redirect()->route('vendors.index', $routeParam); + } + + flash(trans('vendor.undeleted'), 'danger'); + return back(); + } +} diff --git a/app/Policies/Partners/VendorPolicy.php b/app/Policies/Partners/VendorPolicy.php new file mode 100644 index 0000000..1df1785 --- /dev/null +++ b/app/Policies/Partners/VendorPolicy.php @@ -0,0 +1,64 @@ + 'App\Policies\Partners\VendorPolicy', 'App\Entities\Users\Event' => 'App\Policies\EventPolicy', ]; diff --git a/config/simple-crud.php b/config/simple-crud.php new file mode 100644 index 0000000..53d23f6 --- /dev/null +++ b/config/simple-crud.php @@ -0,0 +1,39 @@ + 'layouts.app', + + /* + |-------------------------------------------------------------------------- + | Base Test Class Path + |-------------------------------------------------------------------------- + | + | Base TestCase Path on Laravel application + | + */ + + 'base_test_path' => 'tests/TestCase.php', + + /* + |-------------------------------------------------------------------------- + | Base Test Class + |-------------------------------------------------------------------------- + | + | Base Test Class that used on Laravel application + | according to 'base_test_path' config above + | + */ + + 'base_test_class' => 'Tests\TestCase', + +]; diff --git a/database/factories/VendorFactory.php b/database/factories/VendorFactory.php new file mode 100644 index 0000000..c22d568 --- /dev/null +++ b/database/factories/VendorFactory.php @@ -0,0 +1,11 @@ +define(Vendor::class, function (Faker $faker) { + + return [ + 'name' => $faker->company, + ]; +}); diff --git a/database/migrations/2017_10_26_092017_create_vendors_table.php b/database/migrations/2017_10_26_092017_create_vendors_table.php new file mode 100644 index 0000000..e2b3c62 --- /dev/null +++ b/database/migrations/2017_10_26_092017_create_vendors_table.php @@ -0,0 +1,36 @@ +increments('id'); + $table->string('name', 60); + $table->string('email')->nullable()->unique(); + $table->string('phone')->nullable(); + $table->string('notes')->nullable(); + $table->boolean('is_active')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('vendors'); + } +} diff --git a/resources/lang/id/master.php b/resources/lang/id/master.php index 517a03c..64d1206 100644 --- a/resources/lang/id/master.php +++ b/resources/lang/id/master.php @@ -7,6 +7,7 @@ return [ 'search' => 'Cari Master', 'not_found' => 'Master tidak ditemukan', 'empty' => 'Belum ada Master', + 'back_to_show' => 'Kembali ke detail Master', 'back_to_index' => 'Kembali ke daftar Master', // Actions diff --git a/resources/lang/id/vendor.php b/resources/lang/id/vendor.php new file mode 100644 index 0000000..02bc099 --- /dev/null +++ b/resources/lang/id/vendor.php @@ -0,0 +1,29 @@ + 'Vendor', + 'list' => 'Daftar Vendor', + 'search' => 'Cari Vendor', + 'not_found' => 'Vendor tidak ditemukan', + 'empty' => 'Belum ada Vendor', + 'back_to_show' => 'Back to Vendor Detail', + 'back_to_index' => 'Kembali ke daftar Vendor', + + // Actions + 'create' => 'Input Vendor Baru', + 'created' => 'Input Vendor baru telah berhasil.', + 'show' => 'Detail Vendor', + 'edit' => 'Edit Vendor', + 'update' => 'Update Vendor', + 'updated' => 'Update data Vendor telah berhasil.', + 'delete' => 'Hapus Vendor', + 'delete_confirm' => 'Anda yakin akan menghapus Vendor ini?', + 'deleted' => 'Hapus data Vendor telah berhasil.', + 'undeleted' => 'Data Vendor gagal dihapus.', + 'undeleteable' => 'Data Vendor tidak dapat dihapus.', + + // Attributes + 'name' => 'Nama Vendor', + 'description' => 'Deskripsi Vendor', +]; diff --git a/resources/views/vendors/forms.blade.php b/resources/views/vendors/forms.blade.php new file mode 100644 index 0000000..4be7273 --- /dev/null +++ b/resources/views/vendors/forms.blade.php @@ -0,0 +1,60 @@ +@if (Request::get('action') == 'create') + {!! Form::open(['route' => 'vendors.store']) !!} + {!! FormField::text('name', ['required' => true]) !!} + {!! FormField::email('email') !!} + {!! FormField::text('phone') !!} + {!! FormField::textarea('notes') !!} + {!! Form::submit(trans('vendor.create'), ['class' => 'btn btn-success']) !!} + {{ link_to_route('vendors.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} + {!! Form::close() !!} +@endif +@if (Request::get('action') == 'edit' && $editableVendor) + {!! Form::model($editableVendor, ['route' => ['vendors.update', $editableVendor->id],'method' => 'patch']) !!} + {!! FormField::text('name', ['required' => true]) !!} + {!! FormField::email('email') !!} + {!! FormField::text('phone') !!} + {!! FormField::textarea('notes') !!} + {!! FormField::radios('is_active', ['Non Aktif', 'Aktif']) !!} + @if (request('q')) + {{ Form::hidden('q', request('q')) }} + @endif + @if (request('page')) + {{ Form::hidden('page', request('page')) }} + @endif + {!! Form::submit(trans('vendor.update'), ['class' => 'btn btn-success']) !!} + {{ link_to_route('vendors.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} + {!! Form::close() !!} +@endif +@if (Request::get('action') == 'delete' && $editableVendor) +
{{ $editableVendor->name }}
+ +{{ $editableVendor->email }}
+ +{{ $editableVendor->phone }}
+ +{{ $editableVendor->is_active }}
+ +{{ $editableVendor->notes }}
+ {!! $errors->first('vendor_id', ':message') !!} +| {{ trans('app.table_no') }} | +{{ trans('vendor.name') }} | +{{ trans('contact.email') }} | +{{ trans('contact.phone') }} | +{{ trans('app.status') }} | +{{ trans('app.action') }} | +
|---|---|---|---|---|---|
| {{ $vendors->firstItem() + $key }} | +{{ $vendor->name }} | +{{ $vendor->email }} | +{{ $vendor->phone }} | +{{ $vendor->is_active }} | ++ {!! link_to_route( + 'vendors.index', + trans('app.edit'), + ['action' => 'edit', 'id' => $vendor->id] + Request::only('page', 'q'), + ['id' => 'edit-vendor-' . $vendor->id] + ) !!} | + {!! link_to_route( + 'vendors.index', + trans('app.delete'), + ['action' => 'delete', 'id' => $vendor->id] + Request::only('page', 'q'), + ['id' => 'del-vendor-' . $vendor->id] + ) !!} + | +