PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.5.5
Fluent Support – Helpdesk & Customer Support Ticket System v1.5.5
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Http / Controllers / ProductController.php

ProductController.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.5.5, at app/Http/Controllers/ProductController.php

106 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Http\Controllers;
4
5 use FluentSupport\App\Models\Customer;
6 use FluentSupport\App\Models\Product;
7 use FluentSupport\App\Models\Conversation;
8 use FluentSupport\App\Models\Ticket;
9 use FluentSupport\Framework\Request\Request;
10 use FluentSupport\Framework\Support\Arr;
11
12 class ProductController extends Controller
13 {
14 /**
15 * index method will return the list of product
16 * @param Request $request
17 * @return array
18 */
19 public function index(Request $request)
20 {
21 $products = Product::orderBy('id', 'DESC')->searchBy($request->get('search'))->paginate();
22
23 return [
24 'products' => $products
25 ];
26 }
27
28 /**
29 * get method will get product by id and return
30 * @param Request $request
31 * @param $productId
32 * @return array
33 */
34 public function get(Request $request, $productId)
35 {
36 $product = Product::findOrFail($productId);
37 return [
38 'product' => $product
39 ];
40 }
41
42 /**
43 * creare method will create new product
44 * @param Request $request
45 * @return array
46 * @throws \FluentSupport\Framework\Validator\ValidationException
47 */
48 public function create(Request $request)
49 {
50 $data = $request->all();
51 $this->validate($data, [
52 'title' => 'required'
53 ]);
54
55 $data = wp_unslash($data);
56 $product = Product::create($data);
57
58 return [
59 'message' => __('Product has been successfully created', 'fluent-support'),
60 'product' => $product
61 ];
62 }
63
64
65 /**
66 * update methd will update an exiting product by id
67 * @param Request $request
68 * @param $productId
69 * @return array
70 * @throws \FluentSupport\Framework\Validator\ValidationException
71 */
72 public function update(Request $request, $productId)
73 {
74 $data = $request->all();
75 $this->validate($data, [
76 'title' => 'required'
77 ]);
78
79 $product = Product::findOrFail($productId);
80 $product->fill($data);
81 $product->save();
82
83 return [
84 'message' => __('Product has been updated', 'fluent-support'),
85 'product' => Product::find($productId)
86 ];
87 }
88
89 /**
90 * delete method will delete an existing product by id
91 * @param Request $request
92 * @param $productId
93 * @return array
94 */
95 public function delete(Request $request, $productId)
96 {
97 Product::where('id', $productId)
98 ->delete();
99
100 return [
101 'message' => __('Product has been deleted', 'fluent-support')
102 ];
103 }
104
105 }
106