PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Http / Requests / AttachUserRequest.php

AttachUserRequest.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Http/Requests/AttachUserRequest.php

61 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Http\Requests;
4
5 use FluentCart\App\App;
6 use FluentCart\App\Models\Customer;
7 use FluentCart\App\Models\User;
8 use FluentCart\Framework\Foundation\RequestGuard;
9
10 class AttachUserRequest extends RequestGuard
11 {
12
13 /**
14 * @return array
15 */
16 public function rules(): array
17 {
18 $userId = absint(App::request()->get('user_id'));
19 $user = User::query()->with('customer')->find($userId);
20
21
22 return [
23 'user_id' => [
24 'required', 'string', 'maxLength:50',
25 function ($attribute, $value) use ($user) {
26
27 if (empty($user)) {
28 return __('User not found.', 'fluent-cart');
29 }
30
31 if (!empty($user->customer)) {
32 return (__('User already linked to a customer.', 'fluent-cart'));
33 }
34 return null;
35 }
36 ],
37 ];
38 }
39
40 /**
41 * @return array
42 */
43 public function messages(): array
44 {
45 return [
46 'user_id.required' => esc_html__('User is required.', 'fluent-cart'),
47 'user_id.exists' => esc_html__('User not found.', 'fluent-cart'),
48 ];
49 }
50
51 /**
52 * @return array
53 */
54 public function sanitize(): array
55 {
56 return [
57 'user_id' => 'absint',
58 ];
59 }
60 }
61