@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Password Reset Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'password' => 'Passwords must be at least six characters and match the confirmation.', |
|
17 | - 'reset' => 'Your password has been reset!', |
|
18 | - 'sent' => 'We have e-mailed your password reset link!', |
|
19 | - 'token' => 'This password reset token is invalid.', |
|
20 | - 'user' => "We can't find a user with that e-mail address.", |
|
16 | + 'password' => 'Passwords must be at least six characters and match the confirmation.', |
|
17 | + 'reset' => 'Your password has been reset!', |
|
18 | + 'sent' => 'We have e-mailed your password reset link!', |
|
19 | + 'token' => 'This password reset token is invalid.', |
|
20 | + 'user' => "We can't find a user with that e-mail address.", |
|
21 | 21 | |
22 | 22 | ]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Pagination Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'previous' => '« Previous', |
|
17 | - 'next' => 'Next »', |
|
16 | + 'previous' => '« Previous', |
|
17 | + 'next' => 'Next »', |
|
18 | 18 | |
19 | 19 | ]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Authentication Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'failed' => 'These credentials do not match our records.', |
|
17 | - 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', |
|
16 | + 'failed' => 'These credentials do not match our records.', |
|
17 | + 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', |
|
18 | 18 | |
19 | 19 | ]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Validation Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,74 +13,74 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'accepted' => 'The :attribute must be accepted.', |
|
17 | - 'active_url' => 'The :attribute is not a valid URL.', |
|
18 | - 'after' => 'The :attribute must be a date after :date.', |
|
19 | - 'alpha' => 'The :attribute may only contain letters.', |
|
20 | - 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', |
|
21 | - 'alpha_num' => 'The :attribute may only contain letters and numbers.', |
|
22 | - 'array' => 'The :attribute must be an array.', |
|
23 | - 'before' => 'The :attribute must be a date before :date.', |
|
24 | - 'between' => [ |
|
25 | - 'numeric' => 'The :attribute must be between :min and :max.', |
|
26 | - 'file' => 'The :attribute must be between :min and :max kilobytes.', |
|
27 | - 'string' => 'The :attribute must be between :min and :max characters.', |
|
28 | - 'array' => 'The :attribute must have between :min and :max items.', |
|
29 | - ], |
|
30 | - 'boolean' => 'The :attribute field must be true or false.', |
|
31 | - 'confirmed' => 'The :attribute confirmation does not match.', |
|
32 | - 'date' => 'The :attribute is not a valid date.', |
|
33 | - 'date_format' => 'The :attribute does not match the format :format.', |
|
34 | - 'different' => 'The :attribute and :other must be different.', |
|
35 | - 'digits' => 'The :attribute must be :digits digits.', |
|
36 | - 'digits_between' => 'The :attribute must be between :min and :max digits.', |
|
37 | - 'distinct' => 'The :attribute field has a duplicate value.', |
|
38 | - 'email' => 'The :attribute must be a valid email address.', |
|
39 | - 'exists' => 'The selected :attribute is invalid.', |
|
40 | - 'filled' => 'The :attribute field is required.', |
|
41 | - 'image' => 'The :attribute must be an image.', |
|
42 | - 'in' => 'The selected :attribute is invalid.', |
|
43 | - 'in_array' => 'The :attribute field does not exist in :other.', |
|
44 | - 'integer' => 'The :attribute must be an integer.', |
|
45 | - 'ip' => 'The :attribute must be a valid IP address.', |
|
46 | - 'json' => 'The :attribute must be a valid JSON string.', |
|
47 | - 'max' => [ |
|
48 | - 'numeric' => 'The :attribute may not be greater than :max.', |
|
49 | - 'file' => 'The :attribute may not be greater than :max kilobytes.', |
|
50 | - 'string' => 'The :attribute may not be greater than :max characters.', |
|
51 | - 'array' => 'The :attribute may not have more than :max items.', |
|
52 | - ], |
|
53 | - 'mimes' => 'The :attribute must be a file of type: :values.', |
|
54 | - 'min' => [ |
|
55 | - 'numeric' => 'The :attribute must be at least :min.', |
|
56 | - 'file' => 'The :attribute must be at least :min kilobytes.', |
|
57 | - 'string' => 'The :attribute must be at least :min characters.', |
|
58 | - 'array' => 'The :attribute must have at least :min items.', |
|
59 | - ], |
|
60 | - 'not_in' => 'The selected :attribute is invalid.', |
|
61 | - 'numeric' => 'The :attribute must be a number.', |
|
62 | - 'present' => 'The :attribute field must be present.', |
|
63 | - 'regex' => 'The :attribute format is invalid.', |
|
64 | - 'required' => 'The :attribute field is required.', |
|
65 | - 'required_if' => 'The :attribute field is required when :other is :value.', |
|
66 | - 'required_unless' => 'The :attribute field is required unless :other is in :values.', |
|
67 | - 'required_with' => 'The :attribute field is required when :values is present.', |
|
68 | - 'required_with_all' => 'The :attribute field is required when :values is present.', |
|
69 | - 'required_without' => 'The :attribute field is required when :values is not present.', |
|
70 | - 'required_without_all' => 'The :attribute field is required when none of :values are present.', |
|
71 | - 'same' => 'The :attribute and :other must match.', |
|
72 | - 'size' => [ |
|
73 | - 'numeric' => 'The :attribute must be :size.', |
|
74 | - 'file' => 'The :attribute must be :size kilobytes.', |
|
75 | - 'string' => 'The :attribute must be :size characters.', |
|
76 | - 'array' => 'The :attribute must contain :size items.', |
|
77 | - ], |
|
78 | - 'string' => 'The :attribute must be a string.', |
|
79 | - 'timezone' => 'The :attribute must be a valid zone.', |
|
80 | - 'unique' => 'The :attribute has already been taken.', |
|
81 | - 'url' => 'The :attribute format is invalid.', |
|
16 | + 'accepted' => 'The :attribute must be accepted.', |
|
17 | + 'active_url' => 'The :attribute is not a valid URL.', |
|
18 | + 'after' => 'The :attribute must be a date after :date.', |
|
19 | + 'alpha' => 'The :attribute may only contain letters.', |
|
20 | + 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', |
|
21 | + 'alpha_num' => 'The :attribute may only contain letters and numbers.', |
|
22 | + 'array' => 'The :attribute must be an array.', |
|
23 | + 'before' => 'The :attribute must be a date before :date.', |
|
24 | + 'between' => [ |
|
25 | + 'numeric' => 'The :attribute must be between :min and :max.', |
|
26 | + 'file' => 'The :attribute must be between :min and :max kilobytes.', |
|
27 | + 'string' => 'The :attribute must be between :min and :max characters.', |
|
28 | + 'array' => 'The :attribute must have between :min and :max items.', |
|
29 | + ], |
|
30 | + 'boolean' => 'The :attribute field must be true or false.', |
|
31 | + 'confirmed' => 'The :attribute confirmation does not match.', |
|
32 | + 'date' => 'The :attribute is not a valid date.', |
|
33 | + 'date_format' => 'The :attribute does not match the format :format.', |
|
34 | + 'different' => 'The :attribute and :other must be different.', |
|
35 | + 'digits' => 'The :attribute must be :digits digits.', |
|
36 | + 'digits_between' => 'The :attribute must be between :min and :max digits.', |
|
37 | + 'distinct' => 'The :attribute field has a duplicate value.', |
|
38 | + 'email' => 'The :attribute must be a valid email address.', |
|
39 | + 'exists' => 'The selected :attribute is invalid.', |
|
40 | + 'filled' => 'The :attribute field is required.', |
|
41 | + 'image' => 'The :attribute must be an image.', |
|
42 | + 'in' => 'The selected :attribute is invalid.', |
|
43 | + 'in_array' => 'The :attribute field does not exist in :other.', |
|
44 | + 'integer' => 'The :attribute must be an integer.', |
|
45 | + 'ip' => 'The :attribute must be a valid IP address.', |
|
46 | + 'json' => 'The :attribute must be a valid JSON string.', |
|
47 | + 'max' => [ |
|
48 | + 'numeric' => 'The :attribute may not be greater than :max.', |
|
49 | + 'file' => 'The :attribute may not be greater than :max kilobytes.', |
|
50 | + 'string' => 'The :attribute may not be greater than :max characters.', |
|
51 | + 'array' => 'The :attribute may not have more than :max items.', |
|
52 | + ], |
|
53 | + 'mimes' => 'The :attribute must be a file of type: :values.', |
|
54 | + 'min' => [ |
|
55 | + 'numeric' => 'The :attribute must be at least :min.', |
|
56 | + 'file' => 'The :attribute must be at least :min kilobytes.', |
|
57 | + 'string' => 'The :attribute must be at least :min characters.', |
|
58 | + 'array' => 'The :attribute must have at least :min items.', |
|
59 | + ], |
|
60 | + 'not_in' => 'The selected :attribute is invalid.', |
|
61 | + 'numeric' => 'The :attribute must be a number.', |
|
62 | + 'present' => 'The :attribute field must be present.', |
|
63 | + 'regex' => 'The :attribute format is invalid.', |
|
64 | + 'required' => 'The :attribute field is required.', |
|
65 | + 'required_if' => 'The :attribute field is required when :other is :value.', |
|
66 | + 'required_unless' => 'The :attribute field is required unless :other is in :values.', |
|
67 | + 'required_with' => 'The :attribute field is required when :values is present.', |
|
68 | + 'required_with_all' => 'The :attribute field is required when :values is present.', |
|
69 | + 'required_without' => 'The :attribute field is required when :values is not present.', |
|
70 | + 'required_without_all' => 'The :attribute field is required when none of :values are present.', |
|
71 | + 'same' => 'The :attribute and :other must match.', |
|
72 | + 'size' => [ |
|
73 | + 'numeric' => 'The :attribute must be :size.', |
|
74 | + 'file' => 'The :attribute must be :size kilobytes.', |
|
75 | + 'string' => 'The :attribute must be :size characters.', |
|
76 | + 'array' => 'The :attribute must contain :size items.', |
|
77 | + ], |
|
78 | + 'string' => 'The :attribute must be a string.', |
|
79 | + 'timezone' => 'The :attribute must be a valid zone.', |
|
80 | + 'unique' => 'The :attribute has already been taken.', |
|
81 | + 'url' => 'The :attribute format is invalid.', |
|
82 | 82 | |
83 | - /* |
|
83 | + /* |
|
84 | 84 | |-------------------------------------------------------------------------- |
85 | 85 | | Custom Validation Language Lines |
86 | 86 | |-------------------------------------------------------------------------- |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | | |
92 | 92 | */ |
93 | 93 | |
94 | - 'custom' => [ |
|
95 | - 'attribute-name' => [ |
|
96 | - 'rule-name' => 'custom-message', |
|
97 | - ], |
|
98 | - ], |
|
94 | + 'custom' => [ |
|
95 | + 'attribute-name' => [ |
|
96 | + 'rule-name' => 'custom-message', |
|
97 | + ], |
|
98 | + ], |
|
99 | 99 | |
100 | - /* |
|
100 | + /* |
|
101 | 101 | |-------------------------------------------------------------------------- |
102 | 102 | | Custom Validation Attributes |
103 | 103 | |-------------------------------------------------------------------------- |
@@ -108,6 +108,6 @@ discard block |
||
108 | 108 | | |
109 | 109 | */ |
110 | 110 | |
111 | - 'attributes' => [], |
|
111 | + 'attributes' => [], |
|
112 | 112 | |
113 | 113 | ]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Password Reminder Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'password' => 'يجب أن لا يقل طول كلمة السر عن ستة أحرف، كما يجب أن تتطابق مع حقل التأكيد', |
|
17 | - 'reset' => 'تمت إعادة تعيين كلمة السر', |
|
18 | - 'sent' => 'تم إرسال تفاصيل استعادة كلمة السر الخاصة بك إلى بريدك الإلكتروني', |
|
19 | - 'token' => '.رمز استعادة كلمة السر الذي أدخلته غير صحيح', |
|
20 | - 'user' => 'لم يتم العثور على أيّ حسابٍ بهذا العنوان الإلكتروني', |
|
16 | + 'password' => 'يجب أن لا يقل طول كلمة السر عن ستة أحرف، كما يجب أن تتطابق مع حقل التأكيد', |
|
17 | + 'reset' => 'تمت إعادة تعيين كلمة السر', |
|
18 | + 'sent' => 'تم إرسال تفاصيل استعادة كلمة السر الخاصة بك إلى بريدك الإلكتروني', |
|
19 | + 'token' => '.رمز استعادة كلمة السر الذي أدخلته غير صحيح', |
|
20 | + 'user' => 'لم يتم العثور على أيّ حسابٍ بهذا العنوان الإلكتروني', |
|
21 | 21 | |
22 | 22 | ]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Pagination Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'previous' => '« السابق', |
|
17 | - 'next' => 'التالي »', |
|
16 | + 'previous' => '« السابق', |
|
17 | + 'next' => 'التالي »', |
|
18 | 18 | |
19 | 19 | ]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Authentication Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'failed' => 'بيانات الاعتماد هذه غير متطابقة مع البيانات المسجلة لدينا.', |
|
17 | - 'throttle' => 'عدد كبير جدا من محاولات الدخول. يرجى المحاولة مرة أخرى بعد :seconds ثانية.', |
|
16 | + 'failed' => 'بيانات الاعتماد هذه غير متطابقة مع البيانات المسجلة لدينا.', |
|
17 | + 'throttle' => 'عدد كبير جدا من محاولات الدخول. يرجى المحاولة مرة أخرى بعد :seconds ثانية.', |
|
18 | 18 | |
19 | 19 | ]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Validation Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,76 +13,76 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'accepted' => 'يجب قبول الحقل :attribute', |
|
17 | - 'active_url' => 'الحقل :attribute لا يُمثّل رابطًا صحيحًا', |
|
18 | - 'after' => 'يجب على الحقل :attribute أن يكون تاريخًا لاحقًا للتاريخ :date.', |
|
19 | - 'alpha' => 'يجب أن لا يحتوي الحقل :attribute سوى على حروف', |
|
20 | - 'alpha_dash' => 'يجب أن لا يحتوي الحقل :attribute على حروف، أرقام ومطّات.', |
|
21 | - 'alpha_num' => 'يجب أن يحتوي :attribute على حروفٍ وأرقامٍ فقط', |
|
22 | - 'array' => 'يجب أن يكون الحقل :attribute ًمصفوفة', |
|
23 | - 'before' => 'يجب على الحقل :attribute أن يكون تاريخًا سابقًا للتاريخ :date.', |
|
24 | - 'between' => [ |
|
25 | - 'numeric' => 'يجب أن تكون قيمة :attribute محصورة ما بين :min و :max.', |
|
26 | - 'file' => 'يجب أن يكون حجم الملف :attribute محصورًا ما بين :min و :max كيلوبايت.', |
|
27 | - 'string' => 'يجب أن يكون عدد حروف النّص :attribute محصورًا ما بين :min و :max', |
|
28 | - 'array' => 'يجب أن يحتوي :attribute على عدد من العناصر محصورًا ما بين :min و :max', |
|
29 | - ], |
|
30 | - 'boolean' => 'يجب أن تكون قيمة الحقل :attribute إما true أو false ', |
|
31 | - 'confirmed' => 'حقل التأكيد غير مُطابق للحقل :attribute', |
|
32 | - 'date' => 'الحقل :attribute ليس تاريخًا صحيحًا', |
|
33 | - 'date_format' => 'لا يتوافق الحقل :attribute مع الشكل :format.', |
|
34 | - 'different' => 'يجب أن يكون الحقلان :attribute و :other مُختلفان', |
|
35 | - 'digits' => 'يجب أن يحتوي الحقل :attribute على :digits رقمًا/أرقام', |
|
36 | - 'digits_between' => 'يجب أن يحتوي الحقل :attribute ما بين :min و :max رقمًا/أرقام ', |
|
37 | - 'dimensions' => 'The :attribute has invalid image dimensions.', |
|
38 | - 'distinct' => 'للحقل :attribute قيمة مُكرّرة.', |
|
39 | - 'email' => 'يجب أن يكون :attribute عنوان بريد إلكتروني صحيح البُنية', |
|
40 | - 'exists' => 'الحقل :attribute لاغٍ', |
|
41 | - 'file' => 'The :attribute must be a file.', |
|
42 | - 'filled' => 'الحقل :attribute إجباري', |
|
43 | - 'image' => 'يجب أن يكون الحقل :attribute صورةً', |
|
44 | - 'in' => 'الحقل :attribute لاغٍ', |
|
45 | - 'in_array' => 'الحقل :attribute غير موجود في :other.', |
|
46 | - 'integer' => 'يجب أن يكون الحقل :attribute عددًا صحيحًا', |
|
47 | - 'ip' => 'يجب أن يكون الحقل :attribute عنوان IP ذي بُنية صحيحة', |
|
48 | - 'json' => 'يجب أن يكون الحقل :attribute نصآ من نوع JSON.', |
|
49 | - 'max' => [ |
|
50 | - 'numeric' => 'يجب أن تكون قيمة الحقل :attribute أصغر من :max.', |
|
51 | - 'file' => 'يجب أن يكون حجم الملف :attribute أصغر من :max كيلوبايت', |
|
52 | - 'string' => 'يجب أن لا يتجاوز طول النّص :attribute :max حروفٍ/حرفًا', |
|
53 | - 'array' => 'يجب أن لا يحتوي الحقل :attribute على أكثر من :max عناصر/عنصر.', |
|
54 | - ], |
|
55 | - 'mimes' => 'يجب أن يكون الحقل ملفًا من نوع : :values.', |
|
56 | - 'min' => [ |
|
57 | - 'numeric' => 'يجب أن تكون قيمة الحقل :attribute أكبر من :min.', |
|
58 | - 'file' => 'يجب أن يكون حجم الملف :attribute أكبر من :min كيلوبايت', |
|
59 | - 'string' => 'يجب أن يكون طول النص :attribute أكبر من :min حروفٍ/حرفًا', |
|
60 | - 'array' => 'يجب أن يحتوي الحقل :attribute على الأقل على :min عُنصرًا/عناصر', |
|
61 | - ], |
|
62 | - 'not_in' => 'الحقل :attribute لاغٍ', |
|
63 | - 'numeric' => 'يجب على الحقل :attribute أن يكون رقمًا', |
|
64 | - 'present' => 'The :attribute field must be present.', |
|
65 | - 'regex' => 'صيغة الحقل :attribute .غير صحيحة', |
|
66 | - 'required' => 'الحقل :attribute مطلوب.', |
|
67 | - 'required_if' => 'الحقل :attribute مطلوب في حال ما إذا كان :other يساوي :value.', |
|
68 | - 'required_unless' => 'الحقل :attribute مطلوب في حال ما لم يكن :other يساوي :values.', |
|
69 | - 'required_with' => 'الحقل :attribute إذا توفّر :values.', |
|
70 | - 'required_with_all' => 'الحقل :attribute إذا توفّر :values.', |
|
71 | - 'required_without' => 'الحقل :attribute إذا لم يتوفّر :values.', |
|
72 | - 'required_without_all' => 'الحقل :attribute إذا لم يتوفّر :values.', |
|
73 | - 'same' => 'يجب أن يتطابق الحقل :attribute مع :other', |
|
74 | - 'size' => [ |
|
75 | - 'numeric' => 'يجب أن تكون قيمة :attribute أكبر من :size.', |
|
76 | - 'file' => 'يجب أن يكون حجم الملف :attribute أكبر من :size كيلو بايت.', |
|
77 | - 'string' => 'يجب أن يحتوي النص :attribute عن ما لا يقل عن :size حرفٍ/أحرف.', |
|
78 | - 'array' => 'يجب أن يحتوي الحقل :attribute عن ما لا يقل عن:min عنصرٍ/عناصر', |
|
79 | - ], |
|
80 | - 'string' => 'يجب أن يكون الحقل :attribute نصآ.', |
|
81 | - 'timezone' => 'يجب أن يكون :attribute نطاقًا زمنيًا صحيحًا', |
|
82 | - 'unique' => 'قيمة الحقل :attribute مُستخدمة من قبل', |
|
83 | - 'url' => 'صيغة الرابط :attribute غير صحيحة', |
|
16 | + 'accepted' => 'يجب قبول الحقل :attribute', |
|
17 | + 'active_url' => 'الحقل :attribute لا يُمثّل رابطًا صحيحًا', |
|
18 | + 'after' => 'يجب على الحقل :attribute أن يكون تاريخًا لاحقًا للتاريخ :date.', |
|
19 | + 'alpha' => 'يجب أن لا يحتوي الحقل :attribute سوى على حروف', |
|
20 | + 'alpha_dash' => 'يجب أن لا يحتوي الحقل :attribute على حروف، أرقام ومطّات.', |
|
21 | + 'alpha_num' => 'يجب أن يحتوي :attribute على حروفٍ وأرقامٍ فقط', |
|
22 | + 'array' => 'يجب أن يكون الحقل :attribute ًمصفوفة', |
|
23 | + 'before' => 'يجب على الحقل :attribute أن يكون تاريخًا سابقًا للتاريخ :date.', |
|
24 | + 'between' => [ |
|
25 | + 'numeric' => 'يجب أن تكون قيمة :attribute محصورة ما بين :min و :max.', |
|
26 | + 'file' => 'يجب أن يكون حجم الملف :attribute محصورًا ما بين :min و :max كيلوبايت.', |
|
27 | + 'string' => 'يجب أن يكون عدد حروف النّص :attribute محصورًا ما بين :min و :max', |
|
28 | + 'array' => 'يجب أن يحتوي :attribute على عدد من العناصر محصورًا ما بين :min و :max', |
|
29 | + ], |
|
30 | + 'boolean' => 'يجب أن تكون قيمة الحقل :attribute إما true أو false ', |
|
31 | + 'confirmed' => 'حقل التأكيد غير مُطابق للحقل :attribute', |
|
32 | + 'date' => 'الحقل :attribute ليس تاريخًا صحيحًا', |
|
33 | + 'date_format' => 'لا يتوافق الحقل :attribute مع الشكل :format.', |
|
34 | + 'different' => 'يجب أن يكون الحقلان :attribute و :other مُختلفان', |
|
35 | + 'digits' => 'يجب أن يحتوي الحقل :attribute على :digits رقمًا/أرقام', |
|
36 | + 'digits_between' => 'يجب أن يحتوي الحقل :attribute ما بين :min و :max رقمًا/أرقام ', |
|
37 | + 'dimensions' => 'The :attribute has invalid image dimensions.', |
|
38 | + 'distinct' => 'للحقل :attribute قيمة مُكرّرة.', |
|
39 | + 'email' => 'يجب أن يكون :attribute عنوان بريد إلكتروني صحيح البُنية', |
|
40 | + 'exists' => 'الحقل :attribute لاغٍ', |
|
41 | + 'file' => 'The :attribute must be a file.', |
|
42 | + 'filled' => 'الحقل :attribute إجباري', |
|
43 | + 'image' => 'يجب أن يكون الحقل :attribute صورةً', |
|
44 | + 'in' => 'الحقل :attribute لاغٍ', |
|
45 | + 'in_array' => 'الحقل :attribute غير موجود في :other.', |
|
46 | + 'integer' => 'يجب أن يكون الحقل :attribute عددًا صحيحًا', |
|
47 | + 'ip' => 'يجب أن يكون الحقل :attribute عنوان IP ذي بُنية صحيحة', |
|
48 | + 'json' => 'يجب أن يكون الحقل :attribute نصآ من نوع JSON.', |
|
49 | + 'max' => [ |
|
50 | + 'numeric' => 'يجب أن تكون قيمة الحقل :attribute أصغر من :max.', |
|
51 | + 'file' => 'يجب أن يكون حجم الملف :attribute أصغر من :max كيلوبايت', |
|
52 | + 'string' => 'يجب أن لا يتجاوز طول النّص :attribute :max حروفٍ/حرفًا', |
|
53 | + 'array' => 'يجب أن لا يحتوي الحقل :attribute على أكثر من :max عناصر/عنصر.', |
|
54 | + ], |
|
55 | + 'mimes' => 'يجب أن يكون الحقل ملفًا من نوع : :values.', |
|
56 | + 'min' => [ |
|
57 | + 'numeric' => 'يجب أن تكون قيمة الحقل :attribute أكبر من :min.', |
|
58 | + 'file' => 'يجب أن يكون حجم الملف :attribute أكبر من :min كيلوبايت', |
|
59 | + 'string' => 'يجب أن يكون طول النص :attribute أكبر من :min حروفٍ/حرفًا', |
|
60 | + 'array' => 'يجب أن يحتوي الحقل :attribute على الأقل على :min عُنصرًا/عناصر', |
|
61 | + ], |
|
62 | + 'not_in' => 'الحقل :attribute لاغٍ', |
|
63 | + 'numeric' => 'يجب على الحقل :attribute أن يكون رقمًا', |
|
64 | + 'present' => 'The :attribute field must be present.', |
|
65 | + 'regex' => 'صيغة الحقل :attribute .غير صحيحة', |
|
66 | + 'required' => 'الحقل :attribute مطلوب.', |
|
67 | + 'required_if' => 'الحقل :attribute مطلوب في حال ما إذا كان :other يساوي :value.', |
|
68 | + 'required_unless' => 'الحقل :attribute مطلوب في حال ما لم يكن :other يساوي :values.', |
|
69 | + 'required_with' => 'الحقل :attribute إذا توفّر :values.', |
|
70 | + 'required_with_all' => 'الحقل :attribute إذا توفّر :values.', |
|
71 | + 'required_without' => 'الحقل :attribute إذا لم يتوفّر :values.', |
|
72 | + 'required_without_all' => 'الحقل :attribute إذا لم يتوفّر :values.', |
|
73 | + 'same' => 'يجب أن يتطابق الحقل :attribute مع :other', |
|
74 | + 'size' => [ |
|
75 | + 'numeric' => 'يجب أن تكون قيمة :attribute أكبر من :size.', |
|
76 | + 'file' => 'يجب أن يكون حجم الملف :attribute أكبر من :size كيلو بايت.', |
|
77 | + 'string' => 'يجب أن يحتوي النص :attribute عن ما لا يقل عن :size حرفٍ/أحرف.', |
|
78 | + 'array' => 'يجب أن يحتوي الحقل :attribute عن ما لا يقل عن:min عنصرٍ/عناصر', |
|
79 | + ], |
|
80 | + 'string' => 'يجب أن يكون الحقل :attribute نصآ.', |
|
81 | + 'timezone' => 'يجب أن يكون :attribute نطاقًا زمنيًا صحيحًا', |
|
82 | + 'unique' => 'قيمة الحقل :attribute مُستخدمة من قبل', |
|
83 | + 'url' => 'صيغة الرابط :attribute غير صحيحة', |
|
84 | 84 | |
85 | - /* |
|
85 | + /* |
|
86 | 86 | |-------------------------------------------------------------------------- |
87 | 87 | | Custom Validation Language Lines |
88 | 88 | |-------------------------------------------------------------------------- |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | | |
94 | 94 | */ |
95 | 95 | |
96 | - 'custom' => [ |
|
97 | - 'attribute-name' => [ |
|
98 | - 'rule-name' => 'custom-message', |
|
99 | - ], |
|
100 | - ], |
|
96 | + 'custom' => [ |
|
97 | + 'attribute-name' => [ |
|
98 | + 'rule-name' => 'custom-message', |
|
99 | + ], |
|
100 | + ], |
|
101 | 101 | |
102 | - /* |
|
102 | + /* |
|
103 | 103 | |-------------------------------------------------------------------------- |
104 | 104 | | Custom Validation Attributes |
105 | 105 | |-------------------------------------------------------------------------- |
@@ -110,36 +110,36 @@ discard block |
||
110 | 110 | | |
111 | 111 | */ |
112 | 112 | |
113 | - 'attributes' => [ |
|
114 | - 'name' => 'الاسم', |
|
115 | - 'username' => 'اسم المُستخدم', |
|
116 | - 'email' => 'البريد الالكتروني', |
|
117 | - 'first_name' => 'الاسم', |
|
118 | - 'last_name' => 'اسم العائلة', |
|
119 | - 'password' => 'كلمة السر', |
|
120 | - 'password_confirmation' => 'تأكيد كلمة السر', |
|
121 | - 'city' => 'المدينة', |
|
122 | - 'country' => 'الدولة', |
|
123 | - 'address' => 'العنوان', |
|
124 | - 'phone' => 'الهاتف', |
|
125 | - 'mobile' => 'الجوال', |
|
126 | - 'age' => 'العمر', |
|
127 | - 'sex' => 'الجنس', |
|
128 | - 'gender' => 'النوع', |
|
129 | - 'day' => 'اليوم', |
|
130 | - 'month' => 'الشهر', |
|
131 | - 'year' => 'السنة', |
|
132 | - 'hour' => 'ساعة', |
|
133 | - 'minute' => 'دقيقة', |
|
134 | - 'second' => 'ثانية', |
|
135 | - 'title' => 'اللقب', |
|
136 | - 'content' => 'المُحتوى', |
|
137 | - 'description' => 'الوصف', |
|
138 | - 'excerpt' => 'المُلخص', |
|
139 | - 'date' => 'التاريخ', |
|
140 | - 'time' => 'الوقت', |
|
141 | - 'available' => 'مُتاح', |
|
142 | - 'size' => 'الحجم', |
|
143 | - ], |
|
113 | + 'attributes' => [ |
|
114 | + 'name' => 'الاسم', |
|
115 | + 'username' => 'اسم المُستخدم', |
|
116 | + 'email' => 'البريد الالكتروني', |
|
117 | + 'first_name' => 'الاسم', |
|
118 | + 'last_name' => 'اسم العائلة', |
|
119 | + 'password' => 'كلمة السر', |
|
120 | + 'password_confirmation' => 'تأكيد كلمة السر', |
|
121 | + 'city' => 'المدينة', |
|
122 | + 'country' => 'الدولة', |
|
123 | + 'address' => 'العنوان', |
|
124 | + 'phone' => 'الهاتف', |
|
125 | + 'mobile' => 'الجوال', |
|
126 | + 'age' => 'العمر', |
|
127 | + 'sex' => 'الجنس', |
|
128 | + 'gender' => 'النوع', |
|
129 | + 'day' => 'اليوم', |
|
130 | + 'month' => 'الشهر', |
|
131 | + 'year' => 'السنة', |
|
132 | + 'hour' => 'ساعة', |
|
133 | + 'minute' => 'دقيقة', |
|
134 | + 'second' => 'ثانية', |
|
135 | + 'title' => 'اللقب', |
|
136 | + 'content' => 'المُحتوى', |
|
137 | + 'description' => 'الوصف', |
|
138 | + 'excerpt' => 'المُلخص', |
|
139 | + 'date' => 'التاريخ', |
|
140 | + 'time' => 'الوقت', |
|
141 | + 'available' => 'مُتاح', |
|
142 | + 'size' => 'الحجم', |
|
143 | + ], |
|
144 | 144 | |
145 | 145 | ]; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @param array $relations |
29 | 29 | * @param string $sortBy |
30 | - * @param boolean $desc |
|
30 | + * @param integer $desc |
|
31 | 31 | * @param array $columns |
32 | 32 | * @return collection |
33 | 33 | */ |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param integer $perPage |
44 | 44 | * @param array $relations |
45 | 45 | * @param string $sortBy |
46 | - * @param boolean $desc |
|
46 | + * @param integer $desc |
|
47 | 47 | * @param array $columns |
48 | 48 | * @return collection |
49 | 49 | */ |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param integer $perPage |
62 | 62 | * @param array $relations |
63 | 63 | * @param string $sortBy |
64 | - * @param boolean $desc |
|
64 | + * @param integer $desc |
|
65 | 65 | * @param array $columns |
66 | 66 | * @return collection |
67 | 67 | */ |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * Save the given model to the storage. |
77 | 77 | * |
78 | 78 | * @param array $data |
79 | - * @return mixed |
|
79 | + * @return boolean |
|
80 | 80 | */ |
81 | 81 | public function save(array $data) |
82 | 82 | { |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @param array $conditions array of conditions |
133 | 133 | * @param array $relations |
134 | 134 | * @param string $sortBy |
135 | - * @param boolean $desc |
|
135 | + * @param integer $desc |
|
136 | 136 | * @param array $columns |
137 | 137 | * @return collection |
138 | 138 | */ |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @param array $conditions array of conditions |
165 | 165 | * @param integer $perPage |
166 | 166 | * @param string $sortBy |
167 | - * @param boolean $desc |
|
167 | + * @param integer $desc |
|
168 | 168 | * @param array $columns |
169 | 169 | * @return collection |
170 | 170 | */ |
@@ -8,548 +8,548 @@ |
||
8 | 8 | |
9 | 9 | abstract class BaseRepository implements BaseRepositoryInterface |
10 | 10 | { |
11 | - /** |
|
12 | - * @var object |
|
13 | - */ |
|
14 | - public $model; |
|
11 | + /** |
|
12 | + * @var object |
|
13 | + */ |
|
14 | + public $model; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Init new object. |
|
18 | - * |
|
19 | - * @var mixed model |
|
20 | - * @return void |
|
21 | - */ |
|
22 | - public function __construct($model) |
|
23 | - { |
|
24 | - $this->model = $model; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Fetch all records with relations from the storage. |
|
29 | - * |
|
30 | - * @param array $relations |
|
31 | - * @param string $sortBy |
|
32 | - * @param boolean $desc |
|
33 | - * @param array $columns |
|
34 | - * @return collection |
|
35 | - */ |
|
36 | - public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
37 | - { |
|
38 | - $sort = $desc ? 'desc' : 'asc'; |
|
39 | - return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns); |
|
40 | - } |
|
16 | + /** |
|
17 | + * Init new object. |
|
18 | + * |
|
19 | + * @var mixed model |
|
20 | + * @return void |
|
21 | + */ |
|
22 | + public function __construct($model) |
|
23 | + { |
|
24 | + $this->model = $model; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Fetch all records with relations from the storage. |
|
29 | + * |
|
30 | + * @param array $relations |
|
31 | + * @param string $sortBy |
|
32 | + * @param boolean $desc |
|
33 | + * @param array $columns |
|
34 | + * @return collection |
|
35 | + */ |
|
36 | + public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
37 | + { |
|
38 | + $sort = $desc ? 'desc' : 'asc'; |
|
39 | + return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Fetch all records with relations from storage in pages. |
|
44 | - * |
|
45 | - * @param integer $perPage |
|
46 | - * @param array $relations |
|
47 | - * @param string $sortBy |
|
48 | - * @param boolean $desc |
|
49 | - * @param array $columns |
|
50 | - * @return collection |
|
51 | - */ |
|
52 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
53 | - { |
|
54 | - $sort = $desc ? 'desc' : 'asc'; |
|
55 | - return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Fetch all records with relations based on |
|
60 | - * the given condition from storage in pages. |
|
61 | - * |
|
62 | - * @param array $conditions array of conditions |
|
63 | - * @param integer $perPage |
|
64 | - * @param array $relations |
|
65 | - * @param string $sortBy |
|
66 | - * @param boolean $desc |
|
67 | - * @param array $columns |
|
68 | - * @return collection |
|
69 | - */ |
|
70 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
71 | - { |
|
72 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
73 | - $sort = $desc ? 'desc' : 'asc'; |
|
74 | - return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
75 | - } |
|
42 | + /** |
|
43 | + * Fetch all records with relations from storage in pages. |
|
44 | + * |
|
45 | + * @param integer $perPage |
|
46 | + * @param array $relations |
|
47 | + * @param string $sortBy |
|
48 | + * @param boolean $desc |
|
49 | + * @param array $columns |
|
50 | + * @return collection |
|
51 | + */ |
|
52 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
53 | + { |
|
54 | + $sort = $desc ? 'desc' : 'asc'; |
|
55 | + return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Fetch all records with relations based on |
|
60 | + * the given condition from storage in pages. |
|
61 | + * |
|
62 | + * @param array $conditions array of conditions |
|
63 | + * @param integer $perPage |
|
64 | + * @param array $relations |
|
65 | + * @param string $sortBy |
|
66 | + * @param boolean $desc |
|
67 | + * @param array $columns |
|
68 | + * @return collection |
|
69 | + */ |
|
70 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
71 | + { |
|
72 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
73 | + $sort = $desc ? 'desc' : 'asc'; |
|
74 | + return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Save the given model to the storage. |
|
79 | - * |
|
80 | - * @param array $data |
|
81 | - * @return mixed |
|
82 | - */ |
|
83 | - public function save(array $data) |
|
84 | - { |
|
85 | - \Session::put('locale', 'all'); |
|
86 | - $model = false; |
|
87 | - $relations = []; |
|
88 | - |
|
89 | - \DB::transaction(function () use (&$model, &$relations, $data) { |
|
77 | + /** |
|
78 | + * Save the given model to the storage. |
|
79 | + * |
|
80 | + * @param array $data |
|
81 | + * @return mixed |
|
82 | + */ |
|
83 | + public function save(array $data) |
|
84 | + { |
|
85 | + \Session::put('locale', 'all'); |
|
86 | + $model = false; |
|
87 | + $relations = []; |
|
88 | + |
|
89 | + \DB::transaction(function () use (&$model, &$relations, $data) { |
|
90 | 90 | |
91 | - $model = $this->prepareModel($data); |
|
92 | - $relations = $this->prepareRelations($data, $model); |
|
93 | - $model = $this->saveModel($model, $relations); |
|
94 | - }); |
|
91 | + $model = $this->prepareModel($data); |
|
92 | + $relations = $this->prepareRelations($data, $model); |
|
93 | + $model = $this->saveModel($model, $relations); |
|
94 | + }); |
|
95 | 95 | |
96 | - if (count($relations)) { |
|
97 | - $model->load(...array_keys($relations)); |
|
98 | - } |
|
99 | - |
|
100 | - return $model; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Delete record from the storage based on the given |
|
105 | - * condition. |
|
106 | - * |
|
107 | - * @param var $value condition value |
|
108 | - * @param string $attribute condition column name |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public function delete($value, $attribute = 'id') |
|
112 | - { |
|
113 | - \DB::transaction(function () use ($value, $attribute) { |
|
114 | - $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
115 | - $model->delete(); |
|
116 | - }); |
|
117 | - }); |
|
118 | - } |
|
96 | + if (count($relations)) { |
|
97 | + $model->load(...array_keys($relations)); |
|
98 | + } |
|
99 | + |
|
100 | + return $model; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Delete record from the storage based on the given |
|
105 | + * condition. |
|
106 | + * |
|
107 | + * @param var $value condition value |
|
108 | + * @param string $attribute condition column name |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public function delete($value, $attribute = 'id') |
|
112 | + { |
|
113 | + \DB::transaction(function () use ($value, $attribute) { |
|
114 | + $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
115 | + $model->delete(); |
|
116 | + }); |
|
117 | + }); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Fetch records from the storage based on the given |
|
122 | - * id. |
|
123 | - * |
|
124 | - * @param integer $id |
|
125 | - * @param string[] $relations |
|
126 | - * @param array $columns |
|
127 | - * @return object |
|
128 | - */ |
|
129 | - public function find($id, $relations = [], $columns = ['*']) |
|
130 | - { |
|
131 | - return $this->model->with($relations)->find($id, $columns); |
|
132 | - } |
|
120 | + /** |
|
121 | + * Fetch records from the storage based on the given |
|
122 | + * id. |
|
123 | + * |
|
124 | + * @param integer $id |
|
125 | + * @param string[] $relations |
|
126 | + * @param array $columns |
|
127 | + * @return object |
|
128 | + */ |
|
129 | + public function find($id, $relations = [], $columns = ['*']) |
|
130 | + { |
|
131 | + return $this->model->with($relations)->find($id, $columns); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Fetch records from the storage based on the given |
|
136 | - * condition. |
|
137 | - * |
|
138 | - * @param array $conditions array of conditions |
|
139 | - * @param array $relations |
|
140 | - * @param string $sortBy |
|
141 | - * @param boolean $desc |
|
142 | - * @param array $columns |
|
143 | - * @return collection |
|
144 | - */ |
|
145 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
146 | - { |
|
147 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
148 | - $sort = $desc ? 'desc' : 'asc'; |
|
149 | - return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Fetch the first record from the storage based on the given |
|
154 | - * condition. |
|
155 | - * |
|
156 | - * @param array $conditions array of conditions |
|
157 | - * @param array $relations |
|
158 | - * @param array $columns |
|
159 | - * @return object |
|
160 | - */ |
|
161 | - public function first($conditions, $relations = [], $columns = ['*']) |
|
162 | - { |
|
163 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
164 | - return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Return the deleted models in pages based on the given conditions. |
|
169 | - * |
|
170 | - * @param array $conditions array of conditions |
|
171 | - * @param integer $perPage |
|
172 | - * @param string $sortBy |
|
173 | - * @param boolean $desc |
|
174 | - * @param array $columns |
|
175 | - * @return collection |
|
176 | - */ |
|
177 | - public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
178 | - { |
|
179 | - unset($conditions['page']); |
|
180 | - unset($conditions['perPage']); |
|
181 | - unset($conditions['sortBy']); |
|
182 | - unset($conditions['sort']); |
|
183 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
184 | - $sort = $desc ? 'desc' : 'asc'; |
|
185 | - $model = $this->model->onlyTrashed(); |
|
186 | - |
|
187 | - if (count($conditions['conditionValues'])) { |
|
188 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
189 | - } |
|
190 | - |
|
191 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Restore the deleted model. |
|
196 | - * |
|
197 | - * @param integer $id |
|
198 | - * @return void |
|
199 | - */ |
|
200 | - public function restore($id) |
|
201 | - { |
|
202 | - $model = $this->model->onlyTrashed()->find($id); |
|
203 | - |
|
204 | - if (! $model) { |
|
205 | - \Errors::notFound(class_basename($this->model).' with id : '.$id); |
|
206 | - } |
|
207 | - |
|
208 | - $model->restore(); |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Fill the model with the given data. |
|
213 | - * |
|
214 | - * @param array $data |
|
215 | - * |
|
216 | - * @return object |
|
217 | - */ |
|
218 | - public function prepareModel($data) |
|
219 | - { |
|
220 | - $modelClass = $this->model; |
|
221 | - |
|
222 | - /** |
|
223 | - * If the id is present in the data then select the model for updating, |
|
224 | - * else create new model. |
|
225 | - * @var array |
|
226 | - */ |
|
227 | - $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
228 | - if (! $model) { |
|
229 | - \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Construct the model object with the given data, |
|
234 | - * and if there is a relation add it to relations array, |
|
235 | - * then save the model. |
|
236 | - */ |
|
237 | - foreach ($data as $key => $value) { |
|
238 | - if (array_search($key, $model->getFillable(), true) !== false) { |
|
239 | - /** |
|
240 | - * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
241 | - */ |
|
242 | - $model->$key = $value; |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - return $model; |
|
247 | - } |
|
134 | + /** |
|
135 | + * Fetch records from the storage based on the given |
|
136 | + * condition. |
|
137 | + * |
|
138 | + * @param array $conditions array of conditions |
|
139 | + * @param array $relations |
|
140 | + * @param string $sortBy |
|
141 | + * @param boolean $desc |
|
142 | + * @param array $columns |
|
143 | + * @return collection |
|
144 | + */ |
|
145 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
146 | + { |
|
147 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
148 | + $sort = $desc ? 'desc' : 'asc'; |
|
149 | + return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Fetch the first record from the storage based on the given |
|
154 | + * condition. |
|
155 | + * |
|
156 | + * @param array $conditions array of conditions |
|
157 | + * @param array $relations |
|
158 | + * @param array $columns |
|
159 | + * @return object |
|
160 | + */ |
|
161 | + public function first($conditions, $relations = [], $columns = ['*']) |
|
162 | + { |
|
163 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
164 | + return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Return the deleted models in pages based on the given conditions. |
|
169 | + * |
|
170 | + * @param array $conditions array of conditions |
|
171 | + * @param integer $perPage |
|
172 | + * @param string $sortBy |
|
173 | + * @param boolean $desc |
|
174 | + * @param array $columns |
|
175 | + * @return collection |
|
176 | + */ |
|
177 | + public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
178 | + { |
|
179 | + unset($conditions['page']); |
|
180 | + unset($conditions['perPage']); |
|
181 | + unset($conditions['sortBy']); |
|
182 | + unset($conditions['sort']); |
|
183 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
184 | + $sort = $desc ? 'desc' : 'asc'; |
|
185 | + $model = $this->model->onlyTrashed(); |
|
186 | + |
|
187 | + if (count($conditions['conditionValues'])) { |
|
188 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
189 | + } |
|
190 | + |
|
191 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Restore the deleted model. |
|
196 | + * |
|
197 | + * @param integer $id |
|
198 | + * @return void |
|
199 | + */ |
|
200 | + public function restore($id) |
|
201 | + { |
|
202 | + $model = $this->model->onlyTrashed()->find($id); |
|
203 | + |
|
204 | + if (! $model) { |
|
205 | + \Errors::notFound(class_basename($this->model).' with id : '.$id); |
|
206 | + } |
|
207 | + |
|
208 | + $model->restore(); |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Fill the model with the given data. |
|
213 | + * |
|
214 | + * @param array $data |
|
215 | + * |
|
216 | + * @return object |
|
217 | + */ |
|
218 | + public function prepareModel($data) |
|
219 | + { |
|
220 | + $modelClass = $this->model; |
|
221 | + |
|
222 | + /** |
|
223 | + * If the id is present in the data then select the model for updating, |
|
224 | + * else create new model. |
|
225 | + * @var array |
|
226 | + */ |
|
227 | + $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
228 | + if (! $model) { |
|
229 | + \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Construct the model object with the given data, |
|
234 | + * and if there is a relation add it to relations array, |
|
235 | + * then save the model. |
|
236 | + */ |
|
237 | + foreach ($data as $key => $value) { |
|
238 | + if (array_search($key, $model->getFillable(), true) !== false) { |
|
239 | + /** |
|
240 | + * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
241 | + */ |
|
242 | + $model->$key = $value; |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + return $model; |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Prepare related models based on the given data for the given model. |
|
251 | - * |
|
252 | - * @param array $data |
|
253 | - * @param object $model |
|
254 | - * |
|
255 | - * @return array |
|
256 | - */ |
|
257 | - public function prepareRelations($data, $model) |
|
258 | - { |
|
259 | - /** |
|
260 | - * Init the relation array |
|
261 | - * |
|
262 | - * @var array |
|
263 | - */ |
|
264 | - $relations = []; |
|
265 | - |
|
266 | - /** |
|
267 | - * Construct the model object with the given data, |
|
268 | - * and if there is a relation add it to relations array, |
|
269 | - * then save the model. |
|
270 | - */ |
|
271 | - foreach ($data as $key => $value) { |
|
272 | - /** |
|
273 | - * If the attribute is a relation. |
|
274 | - */ |
|
275 | - $relation = \Str::camel($key); |
|
276 | - if (method_exists($model, $relation) && \Core::$relation()) { |
|
277 | - /** |
|
278 | - * Check if the relation is a collection. |
|
279 | - */ |
|
280 | - if (class_basename($model->$relation) == 'Collection') { |
|
281 | - /** |
|
282 | - * If the relation has no value then marke the relation data |
|
283 | - * related to the model to be deleted. |
|
284 | - */ |
|
285 | - if (! $value || ! count($value)) { |
|
286 | - $relations[$relation] = 'delete'; |
|
287 | - } |
|
288 | - } |
|
289 | - if (is_array($value)) { |
|
290 | - /** |
|
291 | - * Loop through the relation data. |
|
292 | - */ |
|
293 | - foreach ($value as $attr => $val) { |
|
294 | - /** |
|
295 | - * Get the relation model. |
|
296 | - */ |
|
297 | - $relationBaseModel = \Core::$relation()->model; |
|
298 | - |
|
299 | - /** |
|
300 | - * Check if the relation is a collection. |
|
301 | - */ |
|
302 | - if (class_basename($model->$relation) == 'Collection') { |
|
303 | - /** |
|
304 | - * If the id is present in the data then select the relation model for updating, |
|
305 | - * else create new model. |
|
306 | - */ |
|
307 | - $relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
308 | - |
|
309 | - /** |
|
310 | - * If model doesn't exists. |
|
311 | - */ |
|
312 | - if (! $relationModel) { |
|
313 | - \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Loop through the relation attributes. |
|
318 | - */ |
|
319 | - foreach ($val as $attr => $val) { |
|
320 | - /** |
|
321 | - * Prevent the sub relations or attributes not in the fillable. |
|
322 | - */ |
|
323 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) { |
|
324 | - $relationModel->$attr = $val; |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - $relations[$relation][] = $relationModel; |
|
329 | - } else { |
|
330 | - /** |
|
331 | - * Prevent the sub relations. |
|
332 | - */ |
|
333 | - if (gettype($val) !== 'object' && gettype($val) !== 'array') { |
|
334 | - /** |
|
335 | - * If the id is present in the data then select the relation model for updating, |
|
336 | - * else create new model. |
|
337 | - */ |
|
338 | - $relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
339 | - |
|
340 | - /** |
|
341 | - * If model doesn't exists. |
|
342 | - */ |
|
343 | - if (! $relationModel) { |
|
344 | - \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
345 | - } |
|
346 | - |
|
347 | - foreach ($value as $relationAttribute => $relationValue) { |
|
348 | - /** |
|
349 | - * Prevent attributes not in the fillable. |
|
350 | - */ |
|
351 | - if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) { |
|
352 | - $relationModel->$relationAttribute = $relationValue; |
|
353 | - } |
|
354 | - } |
|
355 | - |
|
356 | - $relations[$relation] = $relationModel; |
|
357 | - } |
|
358 | - } |
|
359 | - } |
|
360 | - } |
|
361 | - } |
|
362 | - } |
|
363 | - |
|
364 | - return $relations; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Save the model with related models. |
|
369 | - * |
|
370 | - * @param object $model |
|
371 | - * @param array $relations |
|
372 | - * |
|
373 | - * @return object |
|
374 | - */ |
|
375 | - public function saveModel($model, $relations) |
|
376 | - { |
|
377 | - |
|
378 | - /** |
|
379 | - * Loop through the relations array. |
|
380 | - */ |
|
381 | - foreach ($relations as $key => $value) { |
|
382 | - /** |
|
383 | - * If the relation is marked for delete then delete it. |
|
384 | - */ |
|
385 | - if ($value == 'delete' && $model->$key()->count()) { |
|
386 | - $model->$key()->delete(); |
|
387 | - } elseif (gettype($value) == 'array') { |
|
388 | - /** |
|
389 | - * Save the model. |
|
390 | - */ |
|
391 | - $model->save(); |
|
392 | - $ids = []; |
|
393 | - |
|
394 | - /** |
|
395 | - * Loop through the relations. |
|
396 | - */ |
|
397 | - foreach ($value as $val) { |
|
398 | - switch (class_basename($model->$key())) { |
|
399 | - /** |
|
400 | - * If the relation is one to many then update it's foreign key with |
|
401 | - * the model id and save it then add its id to ids array to delete all |
|
402 | - * relations who's id isn't in the ids array. |
|
403 | - */ |
|
404 | - case 'HasMany': |
|
405 | - $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
406 | - $val->$foreignKeyName = $model->id; |
|
407 | - $val->save(); |
|
408 | - $ids[] = $val->id; |
|
409 | - break; |
|
410 | - |
|
411 | - /** |
|
412 | - * If the relation is many to many then add it's id to the ids array to |
|
413 | - * attache these ids to the model. |
|
414 | - */ |
|
415 | - case 'BelongsToMany': |
|
416 | - $val->save(); |
|
417 | - $ids[] = $val->id; |
|
418 | - break; |
|
419 | - } |
|
420 | - } |
|
421 | - switch (class_basename($model->$key())) { |
|
422 | - /** |
|
423 | - * If the relation is one to many then delete all |
|
424 | - * relations who's id isn't in the ids array. |
|
425 | - */ |
|
426 | - case 'HasMany': |
|
427 | - $model->$key()->whereNotIn('id', $ids)->delete(); |
|
428 | - break; |
|
429 | - |
|
430 | - /** |
|
431 | - * If the relation is many to many then |
|
432 | - * detach the previous data and attach |
|
433 | - * the ids array to the model. |
|
434 | - */ |
|
435 | - case 'BelongsToMany': |
|
436 | - $model->$key()->detach(); |
|
437 | - $model->$key()->attach($ids); |
|
438 | - break; |
|
439 | - } |
|
440 | - } else { |
|
441 | - switch (class_basename($model->$key())) { |
|
442 | - /** |
|
443 | - * If the relation is one to one. |
|
444 | - */ |
|
445 | - case 'HasOne': |
|
446 | - /** |
|
447 | - * Save the model. |
|
448 | - */ |
|
449 | - $model->save(); |
|
450 | - $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
451 | - $value->$foreignKeyName = $model->id; |
|
452 | - $value->save(); |
|
453 | - break; |
|
454 | - case 'BelongsTo': |
|
455 | - /** |
|
456 | - * Save the model. |
|
457 | - */ |
|
458 | - $value->save(); |
|
459 | - $model->$key()->associate($value); |
|
460 | - break; |
|
461 | - } |
|
462 | - } |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * Save the model. |
|
467 | - */ |
|
468 | - $model->save(); |
|
469 | - |
|
470 | - return $model; |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Build the conditions recursively for the retrieving methods. |
|
475 | - * @param array $conditions |
|
476 | - * @return array |
|
477 | - */ |
|
478 | - protected function constructConditions($conditions, $model) |
|
479 | - { |
|
480 | - $conditionString = ''; |
|
481 | - $conditionValues = []; |
|
482 | - foreach ($conditions as $key => $value) { |
|
483 | - if (Str::contains($key, '->')) { |
|
484 | - $key = $this->wrapJsonSelector($key); |
|
485 | - } |
|
486 | - |
|
487 | - if ($key == 'and') { |
|
488 | - $conditions = $this->constructConditions($value, $model); |
|
489 | - $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
490 | - $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
491 | - } elseif ($key == 'or') { |
|
492 | - $conditions = $this->constructConditions($value, $model); |
|
493 | - $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
494 | - $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
495 | - } else { |
|
496 | - if (is_array($value)) { |
|
497 | - $operator = $value['op']; |
|
498 | - if (strtolower($operator) == 'between') { |
|
499 | - $value1 = $value['val1']; |
|
500 | - $value2 = $value['val2']; |
|
501 | - } else { |
|
502 | - $value = Arr::get($value, 'val', ''); |
|
503 | - } |
|
504 | - } else { |
|
505 | - $operator = '='; |
|
506 | - } |
|
249 | + /** |
|
250 | + * Prepare related models based on the given data for the given model. |
|
251 | + * |
|
252 | + * @param array $data |
|
253 | + * @param object $model |
|
254 | + * |
|
255 | + * @return array |
|
256 | + */ |
|
257 | + public function prepareRelations($data, $model) |
|
258 | + { |
|
259 | + /** |
|
260 | + * Init the relation array |
|
261 | + * |
|
262 | + * @var array |
|
263 | + */ |
|
264 | + $relations = []; |
|
265 | + |
|
266 | + /** |
|
267 | + * Construct the model object with the given data, |
|
268 | + * and if there is a relation add it to relations array, |
|
269 | + * then save the model. |
|
270 | + */ |
|
271 | + foreach ($data as $key => $value) { |
|
272 | + /** |
|
273 | + * If the attribute is a relation. |
|
274 | + */ |
|
275 | + $relation = \Str::camel($key); |
|
276 | + if (method_exists($model, $relation) && \Core::$relation()) { |
|
277 | + /** |
|
278 | + * Check if the relation is a collection. |
|
279 | + */ |
|
280 | + if (class_basename($model->$relation) == 'Collection') { |
|
281 | + /** |
|
282 | + * If the relation has no value then marke the relation data |
|
283 | + * related to the model to be deleted. |
|
284 | + */ |
|
285 | + if (! $value || ! count($value)) { |
|
286 | + $relations[$relation] = 'delete'; |
|
287 | + } |
|
288 | + } |
|
289 | + if (is_array($value)) { |
|
290 | + /** |
|
291 | + * Loop through the relation data. |
|
292 | + */ |
|
293 | + foreach ($value as $attr => $val) { |
|
294 | + /** |
|
295 | + * Get the relation model. |
|
296 | + */ |
|
297 | + $relationBaseModel = \Core::$relation()->model; |
|
298 | + |
|
299 | + /** |
|
300 | + * Check if the relation is a collection. |
|
301 | + */ |
|
302 | + if (class_basename($model->$relation) == 'Collection') { |
|
303 | + /** |
|
304 | + * If the id is present in the data then select the relation model for updating, |
|
305 | + * else create new model. |
|
306 | + */ |
|
307 | + $relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
308 | + |
|
309 | + /** |
|
310 | + * If model doesn't exists. |
|
311 | + */ |
|
312 | + if (! $relationModel) { |
|
313 | + \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Loop through the relation attributes. |
|
318 | + */ |
|
319 | + foreach ($val as $attr => $val) { |
|
320 | + /** |
|
321 | + * Prevent the sub relations or attributes not in the fillable. |
|
322 | + */ |
|
323 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) { |
|
324 | + $relationModel->$attr = $val; |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + $relations[$relation][] = $relationModel; |
|
329 | + } else { |
|
330 | + /** |
|
331 | + * Prevent the sub relations. |
|
332 | + */ |
|
333 | + if (gettype($val) !== 'object' && gettype($val) !== 'array') { |
|
334 | + /** |
|
335 | + * If the id is present in the data then select the relation model for updating, |
|
336 | + * else create new model. |
|
337 | + */ |
|
338 | + $relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
339 | + |
|
340 | + /** |
|
341 | + * If model doesn't exists. |
|
342 | + */ |
|
343 | + if (! $relationModel) { |
|
344 | + \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
345 | + } |
|
346 | + |
|
347 | + foreach ($value as $relationAttribute => $relationValue) { |
|
348 | + /** |
|
349 | + * Prevent attributes not in the fillable. |
|
350 | + */ |
|
351 | + if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) { |
|
352 | + $relationModel->$relationAttribute = $relationValue; |
|
353 | + } |
|
354 | + } |
|
355 | + |
|
356 | + $relations[$relation] = $relationModel; |
|
357 | + } |
|
358 | + } |
|
359 | + } |
|
360 | + } |
|
361 | + } |
|
362 | + } |
|
363 | + |
|
364 | + return $relations; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Save the model with related models. |
|
369 | + * |
|
370 | + * @param object $model |
|
371 | + * @param array $relations |
|
372 | + * |
|
373 | + * @return object |
|
374 | + */ |
|
375 | + public function saveModel($model, $relations) |
|
376 | + { |
|
377 | + |
|
378 | + /** |
|
379 | + * Loop through the relations array. |
|
380 | + */ |
|
381 | + foreach ($relations as $key => $value) { |
|
382 | + /** |
|
383 | + * If the relation is marked for delete then delete it. |
|
384 | + */ |
|
385 | + if ($value == 'delete' && $model->$key()->count()) { |
|
386 | + $model->$key()->delete(); |
|
387 | + } elseif (gettype($value) == 'array') { |
|
388 | + /** |
|
389 | + * Save the model. |
|
390 | + */ |
|
391 | + $model->save(); |
|
392 | + $ids = []; |
|
393 | + |
|
394 | + /** |
|
395 | + * Loop through the relations. |
|
396 | + */ |
|
397 | + foreach ($value as $val) { |
|
398 | + switch (class_basename($model->$key())) { |
|
399 | + /** |
|
400 | + * If the relation is one to many then update it's foreign key with |
|
401 | + * the model id and save it then add its id to ids array to delete all |
|
402 | + * relations who's id isn't in the ids array. |
|
403 | + */ |
|
404 | + case 'HasMany': |
|
405 | + $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
406 | + $val->$foreignKeyName = $model->id; |
|
407 | + $val->save(); |
|
408 | + $ids[] = $val->id; |
|
409 | + break; |
|
410 | + |
|
411 | + /** |
|
412 | + * If the relation is many to many then add it's id to the ids array to |
|
413 | + * attache these ids to the model. |
|
414 | + */ |
|
415 | + case 'BelongsToMany': |
|
416 | + $val->save(); |
|
417 | + $ids[] = $val->id; |
|
418 | + break; |
|
419 | + } |
|
420 | + } |
|
421 | + switch (class_basename($model->$key())) { |
|
422 | + /** |
|
423 | + * If the relation is one to many then delete all |
|
424 | + * relations who's id isn't in the ids array. |
|
425 | + */ |
|
426 | + case 'HasMany': |
|
427 | + $model->$key()->whereNotIn('id', $ids)->delete(); |
|
428 | + break; |
|
429 | + |
|
430 | + /** |
|
431 | + * If the relation is many to many then |
|
432 | + * detach the previous data and attach |
|
433 | + * the ids array to the model. |
|
434 | + */ |
|
435 | + case 'BelongsToMany': |
|
436 | + $model->$key()->detach(); |
|
437 | + $model->$key()->attach($ids); |
|
438 | + break; |
|
439 | + } |
|
440 | + } else { |
|
441 | + switch (class_basename($model->$key())) { |
|
442 | + /** |
|
443 | + * If the relation is one to one. |
|
444 | + */ |
|
445 | + case 'HasOne': |
|
446 | + /** |
|
447 | + * Save the model. |
|
448 | + */ |
|
449 | + $model->save(); |
|
450 | + $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
451 | + $value->$foreignKeyName = $model->id; |
|
452 | + $value->save(); |
|
453 | + break; |
|
454 | + case 'BelongsTo': |
|
455 | + /** |
|
456 | + * Save the model. |
|
457 | + */ |
|
458 | + $value->save(); |
|
459 | + $model->$key()->associate($value); |
|
460 | + break; |
|
461 | + } |
|
462 | + } |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * Save the model. |
|
467 | + */ |
|
468 | + $model->save(); |
|
469 | + |
|
470 | + return $model; |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Build the conditions recursively for the retrieving methods. |
|
475 | + * @param array $conditions |
|
476 | + * @return array |
|
477 | + */ |
|
478 | + protected function constructConditions($conditions, $model) |
|
479 | + { |
|
480 | + $conditionString = ''; |
|
481 | + $conditionValues = []; |
|
482 | + foreach ($conditions as $key => $value) { |
|
483 | + if (Str::contains($key, '->')) { |
|
484 | + $key = $this->wrapJsonSelector($key); |
|
485 | + } |
|
486 | + |
|
487 | + if ($key == 'and') { |
|
488 | + $conditions = $this->constructConditions($value, $model); |
|
489 | + $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
490 | + $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
491 | + } elseif ($key == 'or') { |
|
492 | + $conditions = $this->constructConditions($value, $model); |
|
493 | + $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
494 | + $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
495 | + } else { |
|
496 | + if (is_array($value)) { |
|
497 | + $operator = $value['op']; |
|
498 | + if (strtolower($operator) == 'between') { |
|
499 | + $value1 = $value['val1']; |
|
500 | + $value2 = $value['val2']; |
|
501 | + } else { |
|
502 | + $value = Arr::get($value, 'val', ''); |
|
503 | + } |
|
504 | + } else { |
|
505 | + $operator = '='; |
|
506 | + } |
|
507 | 507 | |
508 | - if (strtolower($operator) == 'between') { |
|
509 | - $conditionString .= $key.' >= ? and '; |
|
510 | - $conditionValues[] = $value1; |
|
511 | - |
|
512 | - $conditionString .= $key.' <= ? {op} '; |
|
513 | - $conditionValues[] = $value2; |
|
514 | - } elseif (strtolower($operator) == 'in') { |
|
515 | - $conditionValues = array_merge($conditionValues, $value); |
|
516 | - $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
|
517 | - $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
518 | - } elseif (strtolower($operator) == 'null') { |
|
519 | - $conditionString .= $key.' is null {op} '; |
|
520 | - } elseif (strtolower($operator) == 'not null') { |
|
521 | - $conditionString .= $key.' is not null {op} '; |
|
522 | - } elseif (strtolower($operator) == 'has') { |
|
523 | - $sql = $model->withTrashed()->has($key)->toSql(); |
|
524 | - $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
|
525 | - $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
526 | - $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
527 | - } else { |
|
528 | - $conditionString .= $key.' '.$operator.' ? {op} '; |
|
529 | - $conditionValues[] = $value; |
|
530 | - } |
|
531 | - } |
|
532 | - } |
|
533 | - $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
534 | - return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Wrap the given JSON selector. |
|
539 | - * |
|
540 | - * @param string $value |
|
541 | - * @return string |
|
542 | - */ |
|
543 | - protected function wrapJsonSelector($value) |
|
544 | - { |
|
545 | - $removeLast = strpos($value, ')'); |
|
546 | - $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
|
547 | - $path = explode('->', $value); |
|
548 | - $field = array_shift($path); |
|
549 | - $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
550 | - return '"'.$part.'"'; |
|
551 | - })->implode('.')); |
|
508 | + if (strtolower($operator) == 'between') { |
|
509 | + $conditionString .= $key.' >= ? and '; |
|
510 | + $conditionValues[] = $value1; |
|
511 | + |
|
512 | + $conditionString .= $key.' <= ? {op} '; |
|
513 | + $conditionValues[] = $value2; |
|
514 | + } elseif (strtolower($operator) == 'in') { |
|
515 | + $conditionValues = array_merge($conditionValues, $value); |
|
516 | + $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
|
517 | + $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
518 | + } elseif (strtolower($operator) == 'null') { |
|
519 | + $conditionString .= $key.' is null {op} '; |
|
520 | + } elseif (strtolower($operator) == 'not null') { |
|
521 | + $conditionString .= $key.' is not null {op} '; |
|
522 | + } elseif (strtolower($operator) == 'has') { |
|
523 | + $sql = $model->withTrashed()->has($key)->toSql(); |
|
524 | + $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
|
525 | + $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
526 | + $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
527 | + } else { |
|
528 | + $conditionString .= $key.' '.$operator.' ? {op} '; |
|
529 | + $conditionValues[] = $value; |
|
530 | + } |
|
531 | + } |
|
532 | + } |
|
533 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
534 | + return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Wrap the given JSON selector. |
|
539 | + * |
|
540 | + * @param string $value |
|
541 | + * @return string |
|
542 | + */ |
|
543 | + protected function wrapJsonSelector($value) |
|
544 | + { |
|
545 | + $removeLast = strpos($value, ')'); |
|
546 | + $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
|
547 | + $path = explode('->', $value); |
|
548 | + $field = array_shift($path); |
|
549 | + $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
550 | + return '"'.$part.'"'; |
|
551 | + })->implode('.')); |
|
552 | 552 | |
553 | - return $removeLast === false ? $result : $result.')'; |
|
554 | - } |
|
553 | + return $removeLast === false ? $result : $result.')'; |
|
554 | + } |
|
555 | 555 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function __construct($model) |
23 | 23 | { |
24 | - $this->model = $model; |
|
24 | + $this->model = $model; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $model = false; |
87 | 87 | $relations = []; |
88 | 88 | |
89 | - \DB::transaction(function () use (&$model, &$relations, $data) { |
|
89 | + \DB::transaction(function() use (&$model, &$relations, $data) { |
|
90 | 90 | |
91 | 91 | $model = $this->prepareModel($data); |
92 | 92 | $relations = $this->prepareRelations($data, $model); |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function delete($value, $attribute = 'id') |
112 | 112 | { |
113 | - \DB::transaction(function () use ($value, $attribute) { |
|
114 | - $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
113 | + \DB::transaction(function() use ($value, $attribute) { |
|
114 | + $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function($model) { |
|
115 | 115 | $model->delete(); |
116 | 116 | }); |
117 | 117 | }); |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | { |
202 | 202 | $model = $this->model->onlyTrashed()->find($id); |
203 | 203 | |
204 | - if (! $model) { |
|
204 | + if ( ! $model) { |
|
205 | 205 | \Errors::notFound(class_basename($this->model).' with id : '.$id); |
206 | 206 | } |
207 | 207 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @var array |
226 | 226 | */ |
227 | 227 | $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
228 | - if (! $model) { |
|
228 | + if ( ! $model) { |
|
229 | 229 | \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']); |
230 | 230 | } |
231 | 231 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * If the relation has no value then marke the relation data |
283 | 283 | * related to the model to be deleted. |
284 | 284 | */ |
285 | - if (! $value || ! count($value)) { |
|
285 | + if ( ! $value || ! count($value)) { |
|
286 | 286 | $relations[$relation] = 'delete'; |
287 | 287 | } |
288 | 288 | } |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | /** |
310 | 310 | * If model doesn't exists. |
311 | 311 | */ |
312 | - if (! $relationModel) { |
|
312 | + if ( ! $relationModel) { |
|
313 | 313 | \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
314 | 314 | } |
315 | 315 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | /** |
341 | 341 | * If model doesn't exists. |
342 | 342 | */ |
343 | - if (! $relationModel) { |
|
343 | + if ( ! $relationModel) { |
|
344 | 344 | \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
345 | 345 | } |
346 | 346 | |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
547 | 547 | $path = explode('->', $value); |
548 | 548 | $field = array_shift($path); |
549 | - $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
549 | + $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function($part) { |
|
550 | 550 | return '"'.$part.'"'; |
551 | 551 | })->implode('.')); |
552 | 552 |