diff --git a/DataTables/EducationDataTable.php b/DataTables/EducationDataTable.php index fcb40f1..30c1a7b 100644 --- a/DataTables/EducationDataTable.php +++ b/DataTables/EducationDataTable.php @@ -28,11 +28,12 @@ }) ->addIndexColumn() ->addColumn('status', function ($model) { - return $model->status == 1 ? 'Active' : 'Inactive'; + return view('master::education._status', compact('model')); }) ->addColumn('action', function ($model) { return view('master::education._action', compact('model')); - }); + }) + ->rawColumns(['status','action']); } /** @@ -55,7 +56,7 @@ public function html() { return $this->builder() - ->setTableId('education-table') + ->setTableId('master-education-table') ->columns($this->getColumns()) ->minifiedAjax() ->orderBy(1, 'asc') @@ -79,10 +80,11 @@ return [ Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false), Column::make('name')->title(__('Name')), - Column::make('status')->title(__('Status')), + Column::computed('status')->title(__('Status'))->width(50)->addClass('text-center')->exportable(false), Column::computed('action') ->exportable(false) ->printable(false) + ->width(100) ->addClass('text-center') ->responsivePriority(-1), ]; diff --git a/Database/Seeders/EducationSeeder.php b/Database/Seeders/EducationSeeder.php new file mode 100644 index 0000000..d113001 --- /dev/null +++ b/Database/Seeders/EducationSeeder.php @@ -0,0 +1,41 @@ +data(); + + foreach ($data as $value) { + Education::create([ + 'name' => $value['name'], + ]); + } + } + + public function data() + { + return [ + ['name' => 'Tidak / Belum Sekolah'], + ['name' => 'Belum Tamat SD / Sederajat'], + ['name' => 'Tamat SD / Sederajat'], + ['name' => 'SLTP / Sederajat'], + ['name' => 'SLTA / Sederajat'], + ['name' => 'Diploma I / II'], + ['name' => 'Akademi / Diploma III / Sarjana Muda'], + ['name' => 'Diploma IV / Strata I'], + ['name' => 'Strata II'], + ['name' => 'Strata III'] + ]; + } + } diff --git a/Entities/Education.php b/Entities/Education.php index ffa75b8..6f27346 100644 --- a/Entities/Education.php +++ b/Entities/Education.php @@ -7,6 +7,8 @@ class Education extends BaseModel { + protected $table = 'educations'; + protected $fillable = [ 'name', 'status', diff --git a/Http/Controllers/EducationController.php b/Http/Controllers/EducationController.php index 624023c..db44db7 100644 --- a/Http/Controllers/EducationController.php +++ b/Http/Controllers/EducationController.php @@ -128,7 +128,7 @@ * * @return Renderable */ - public function update(UpdateEducationRequest $request, Education $company) + public function update(UpdateEducationRequest $request, Education $education) { if (is_null($this->user) || !$this->user->can($this->module->alias . '.update')) { abort(403, 'Sorry !! You are Unauthorized to update any ' . $this->module->alias . ' !'); @@ -140,7 +140,7 @@ // Update the Education... if ($validated) { try { - $company->update($validated); + $education->update($validated); echo json_encode(['status' => 'success', 'message' => $this->module->name . ' education updated successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => $this->module->name . ' education updated failed.']); @@ -158,14 +158,14 @@ * * @return Renderable */ - public function destroy(Education $company) + public function destroy(Education $education) { if (is_null($this->user) || !$this->user->can($this->module->alias . '.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any ' . $this->module->alias . ' !'); } try { - $company->delete(); + $education->delete(); echo json_encode(['status' => 'success', 'message' => $this->module->name . ' education deleted successfully.']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => $this->module->name . ' education deleted failed.']); diff --git a/Http/Requests/Education/StoreEducationRequest.php b/Http/Requests/Education/StoreEducationRequest.php index f62b44d..b53ef78 100644 --- a/Http/Requests/Education/StoreEducationRequest.php +++ b/Http/Requests/Education/StoreEducationRequest.php @@ -2,13 +2,13 @@ namespace Modules\Master\Http\Requests\Education; - use Illuminate\Foundation\Http\FormRequest; use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Validation\ValidationException; use Illuminate\Validation\Validator; + use Modules\Master\Http\Requests\MasterRequest; use Symfony\Component\HttpFoundation\JsonResponse; - class StoreEducationRequest extends FormRequest + class StoreEducationRequest extends MasterRequest { /** * Determine if the user is authorized to make this request. @@ -29,7 +29,7 @@ { return [ 'name' => 'required|string|max:50|unique:educations,name', - 'status' => 'nullable|string|max:1', + 'status' => 'nullable|integer|max:1', ]; } diff --git a/Http/Requests/Education/UpdateEducationRequest.php b/Http/Requests/Education/UpdateEducationRequest.php index c6b8a15..7a88fb9 100644 --- a/Http/Requests/Education/UpdateEducationRequest.php +++ b/Http/Requests/Education/UpdateEducationRequest.php @@ -2,13 +2,13 @@ namespace Modules\Master\Http\Requests\Education; - use Illuminate\Foundation\Http\FormRequest; use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Validation\ValidationException; use Illuminate\Validation\Validator; + use Modules\Master\Http\Requests\MasterRequest; use Symfony\Component\HttpFoundation\JsonResponse; - class UpdateEducationRequest extends FormRequest + class UpdateEducationRequest extends MasterRequest { /** * Determine if the user is authorized to make this request. @@ -28,8 +28,8 @@ : array { return [ - 'name' => 'required|string|max:50|unique:educations,name', $this->education->id, - 'status' => 'nullable|string|max:1', + 'name' => 'required|string|max:50|unique:educations,name,'. $this->education->id, + 'status' => 'nullable|integer|max:1', ]; } diff --git a/Resources/views/education/_action.blade.php b/Resources/views/education/_action.blade.php new file mode 100644 index 0000000..a32eac2 --- /dev/null +++ b/Resources/views/education/_action.blade.php @@ -0,0 +1,13 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp +
+ + {!! getIcon("pencil", "fs-1 text-info","duotune") !!} + + + {!! Form::open(['method' => 'DELETE','route' => [$route[0].'.'.$route[1].'.destroy', $model->id],'class'=>'']) !!} + {{ Form::button(getIcon("trash", "fs-1 text-danger","duotune"), ['type' => 'submit', 'class' => 'delete btn btn-icon btn-bg-light btn-active-light-danger btn-sm'] ) }} + {!! Form::close() !!} +
diff --git a/Resources/views/education/_form.blade.php b/Resources/views/education/_form.blade.php new file mode 100644 index 0000000..94647e5 --- /dev/null +++ b/Resources/views/education/_form.blade.php @@ -0,0 +1,64 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp + + + + diff --git a/Resources/views/education/_status.blade.php b/Resources/views/education/_status.blade.php new file mode 100644 index 0000000..1b62790 --- /dev/null +++ b/Resources/views/education/_status.blade.php @@ -0,0 +1,10 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp + +{!! Form::open(['method' => 'PUT','route' => [$route[0].'.'.$route[1].'.update', $model->id],'class'=>'']) !!} +
+ status==1 ? 'checked' : '' }} type="checkbox" name="status" id="status"/> + +
+{!! Form::close() !!} diff --git a/Resources/views/education/_table.blade.php b/Resources/views/education/_table.blade.php new file mode 100644 index 0000000..75ee5cc --- /dev/null +++ b/Resources/views/education/_table.blade.php @@ -0,0 +1,132 @@ + +{{ $dataTable->table() }} + + +{{-- Inject Scripts --}} +@section('scripts') + {{ $dataTable->scripts() }} +@endsection + +@push('customscript') + @php + $route = explode('.', Route::currentRouteName()); + @endphp + + +@endpush + +@section('styles') + +@endsection diff --git a/Resources/views/education/index.blade.php b/Resources/views/education/index.blade.php new file mode 100644 index 0000000..a003fdd --- /dev/null +++ b/Resources/views/education/index.blade.php @@ -0,0 +1,135 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp + + + +
+ +
+
+
+ + + + + + + + + +
+ + +
+ + +
+ +
+ + + + + + + +
+ + +
+
+
+ @include('master::'.$route[1].'._table') + @include('master::'.$route[1].'._form') +
+ +
+ + @push('customscript') + + @endpush +