add crud api global setting and make global api response and handle response web and api on bootstrap app
This commit is contained in:
@@ -6,10 +6,12 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\GlobalSettingRequest;
|
||||
use App\Http\Resources\GlobalSettingResource;
|
||||
use App\Models\GlobalSetting;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Traits\GlobalApiResponse;
|
||||
use Exception;
|
||||
|
||||
class GlobalSettingsController extends Controller
|
||||
{
|
||||
use GlobalApiResponse;
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
@@ -25,15 +27,10 @@ class GlobalSettingsController extends Controller
|
||||
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()
|
||||
]
|
||||
);
|
||||
return $this->resError($e->getMessage(), null, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,15 +39,36 @@ class GlobalSettingsController extends Controller
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
try{
|
||||
$data = GlobalSetting::find($id);
|
||||
if(!$data){
|
||||
return $this->resError("Invalid id", null, 404);
|
||||
}
|
||||
return new GlobalSettingResource($data);
|
||||
}catch(Exception $e){
|
||||
return $this->resError($e->getMessage(), null, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
public function update(GlobalSettingRequest $request, string $id)
|
||||
{
|
||||
//
|
||||
try{
|
||||
|
||||
$data = GlobalSetting::find($id);
|
||||
if(!$data){
|
||||
return $this->resError("Invalid id", null, 400);
|
||||
}
|
||||
|
||||
$data->update($request->validated());
|
||||
|
||||
return new GlobalSettingResource($data);
|
||||
|
||||
}catch(Exception $e){
|
||||
return $this->resError($e->getMessage(), null, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +76,17 @@ class GlobalSettingsController extends Controller
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
try{
|
||||
$data = GlobalSetting::find($id);
|
||||
if(!$data){
|
||||
return $this->resError("Invalid id", null, 404);
|
||||
}
|
||||
|
||||
$data->delete();
|
||||
|
||||
return new GlobalSettingResource($data);
|
||||
}catch(Exception $e){
|
||||
return $this->resError($e->getMessage(), null, $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user