85 lines
1.9 KiB
PHP
Raw Normal View History

2017-11-18 12:47:57 +03:00
<?php
namespace App\Http\Controllers\Api\Settings;
2019-11-16 10:21:14 +03:00
use App\Abstracts\Http\ApiController;
2017-11-18 12:47:57 +03:00
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());
2020-08-11 16:52:10 +03:00
return $this->response->created(route('api.settings.show', $setting->id));
2017-11-18 12:47:57 +03:00
}
/**
* 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();
}
}