/ app / Http / Services / ToeCategoryService.php
ToeCategoryService.php
 1  <?php
 2  
 3  namespace App\Http\Services;
 4  
 5  use App\Models\TOEType;
 6  use Exception;
 7  
 8  class ToeCategoryService
 9  {
10      /**
11       * Display a listing of the resource.
12       *
13       * @return \Illuminate\Http\Response
14       */
15      public static function index()
16      {
17          return TOEType::with('toes')->orderBy('name', 'asc')->paginate(10);
18      }
19  
20      /**
21       * Create a resource
22       *
23       * @return \Illuminate\Http\Response
24       */
25      public static function create(array $data)
26      {
27          if (TOEType::create($data)) {
28              return true;
29          } else {
30              throw new Exception(__('toes.category.notifications.create.error.message'));
31          }
32      }
33  
34      /**
35       * Destroy a resource
36       *
37       * @return \Illuminate\Http\Response
38       */
39      public static function remove(int $toeCategoryId)
40      {
41          if (TOEType::destroy($toeCategoryId)) {
42              return true;
43          } else {
44              throw new Exception(__('toes.category.notifications.remove.error.message'));
45          }
46      }
47  
48      /**
49       * Update a resource
50       *
51       * @return \Illuminate\Http\Response
52       */
53      public static function update(array $data, int $entityId)
54      {
55          // Params
56          $toeCategory = TOEType::findOrFail($entityId);
57          $toeCategory->name = $data['name'];
58          $toeCategory->code = $data['code'];
59  
60          if ($toeCategory->save()) {
61              return true;
62          } else {
63              throw new Exception(__('toes.category.notifications.create.error.message'));
64          }
65      }
66  
67      /**
68       * Display a listing of the resource.
69       *
70       * @return \Illuminate\Http\Response
71       */
72      public static function find(int $normGroupId)
73      {
74          return TOEType::where('id', $normGroupId)->first();
75      }
76  }