PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.4.2
Fluent Support – Helpdesk & Customer Support Ticket System v1.4.2
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.4.2, at app/Http/Controllers/ProductController.php

75 lines 1.8 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 public function index(Request $request)
15 {
16 $products = Product::orderBy('id', 'DESC')->searchBy($request->get('search'))->paginate();
17
18 return [
19 'products' => $products
20 ];
21 }
22
23 public function get(Request $request, $productId)
24 {
25 $product = Product::findOrFail($productId);
26 return [
27 'product' => $product
28 ];
29 }
30
31 public function create(Request $request)
32 {
33 $data = $request->all();
34 $this->validate($data, [
35 'title' => 'required'
36 ]);
37
38 $data = wp_unslash($data);
39 $product = Product::create($data);
40
41 return [
42 'message' => __('Product has been successfully created', 'fluent-support'),
43 'product' => $product
44 ];
45 }
46
47 public function update(Request $request, $productId)
48 {
49 $data = $request->all();
50 $this->validate($data, [
51 'title' => 'required'
52 ]);
53
54 $product = Product::findOrFail($productId);
55 $product->fill($data);
56 $product->save();
57
58 return [
59 'message' => __('Product has been updated', 'fluent-support'),
60 'product' => Product::find($productId)
61 ];
62 }
63
64 public function delete(Request $request, $productId)
65 {
66 Product::where('id', $productId)
67 ->delete();
68
69 return [
70 'message' => __('Product has been deleted', 'fluent-support')
71 ];
72 }
73
74 }
75