fixed #83
This commit is contained in:
parent
5b9d9d1b03
commit
eb53a7484e
84
app/Http/Controllers/Api/Settings/Settings.php
Normal file
84
app/Http/Controllers/Api/Settings/Settings.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\Setting\Setting as Request;
|
||||
use App\Models\Setting\Setting;
|
||||
use App\Transformers\Setting\Setting as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Settings extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$settings = Setting::all();
|
||||
|
||||
return $this->response->collection($settings, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int|string $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or key
|
||||
if (is_numeric($id)) {
|
||||
$setting = Setting::find($id);
|
||||
} else {
|
||||
$setting = Setting::where('key', $id)->first();
|
||||
}
|
||||
|
||||
return $this->response->item($setting, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$setting = Setting::create($request->all());
|
||||
|
||||
return $this->response->created(url('api/settings/'.$setting->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $setting
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Setting $setting, Request $request)
|
||||
{
|
||||
$setting->update($request->all());
|
||||
|
||||
return $this->response->item($setting->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Setting $setting
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Setting $setting)
|
||||
{
|
||||
$setting->delete();
|
||||
|
||||
return $this->response->noContent();
|
||||
}
|
||||
}
|
23
app/Transformers/Setting/Setting.php
Normal file
23
app/Transformers/Setting/Setting.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Setting;
|
||||
|
||||
use App\Models\Setting\Setting as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class Setting extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Model $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'key' => $model->key,
|
||||
'value' => $model->value,
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user