diff --git a/app/Http/Controllers/Api/GlobalSettingsController.php b/app/Http/Controllers/Api/GlobalSettingsController.php new file mode 100644 index 0000000..00f8a3d --- /dev/null +++ b/app/Http/Controllers/Api/GlobalSettingsController.php @@ -0,0 +1,63 @@ +paginate()); + } + + /** + * Store a newly created resource in storage. + */ + public function store(GlobalSettingRequest $request) + { + try { + //code... + $data = GlobalSetting::create($request->validated()); + return new GlobalSettingResource($data); + } catch (\Exception $e) { + return response()->json( + [ + "errors" => $e->getMessage() + ] + ); + } + } + + /** + * Display the specified resource. + */ + public function show(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } +} diff --git a/app/Http/Requests/GlobalSettingRequest.php b/app/Http/Requests/GlobalSettingRequest.php new file mode 100644 index 0000000..1525da6 --- /dev/null +++ b/app/Http/Requests/GlobalSettingRequest.php @@ -0,0 +1,31 @@ +|string> + */ + public function rules(): array + { + return [ + 'key' => 'required|unique:global_settings', + 'value' => 'required', + 'type' => 'nullable', + 'description' => 'nullable' + ]; + } +} diff --git a/app/Http/Resources/GlobalSettingResource.php b/app/Http/Resources/GlobalSettingResource.php new file mode 100644 index 0000000..b1ea867 --- /dev/null +++ b/app/Http/Resources/GlobalSettingResource.php @@ -0,0 +1,24 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'key' => $this->key, + 'value' => $this->value, + 'type' => $this->type, + 'description' => $this->description + ]; + } +} diff --git a/app/Models/GlobalSetting.php b/app/Models/GlobalSetting.php new file mode 100644 index 0000000..0d2c9f3 --- /dev/null +++ b/app/Models/GlobalSetting.php @@ -0,0 +1,14 @@ +id(); + $table->string('key')->unique(); + $table->text('value'); + $table->string('type')->nullable(); + $table->string('description')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('global_settings'); + } +}; diff --git a/routes/api.php b/routes/api.php index 15b2c75..1fc07d7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,7 @@ name('api.task.submit'); // import datasource -Route::apiResource('import-datasource',ImportDatasourceController::class); \ No newline at end of file +Route::apiResource('import-datasource',ImportDatasourceController::class); + +// global setting +Route::apiResource('global-settings', GlobalSettingsController::class); \ No newline at end of file