Blame view

app/Http/Controllers/Api/Settings/Settings.php 1.94 KB
b7c7a5f6   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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();
      }
  }