Completed
Push — master ( b819b4...8115f1 )
by Sherif
14:17
created
lang/ar/passwords.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 ];
Please login to merge, or discard this patch.
lang/ar/pagination.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-    /*
5
+	/*
6 6
     |--------------------------------------------------------------------------
7 7
     | Pagination Language Lines
8 8
     |--------------------------------------------------------------------------
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     |
14 14
     */
15 15
 
16
-    'previous' => '« السابق',
17
-    'next'     => 'التالي »',
16
+	'previous' => '« السابق',
17
+	'next'     => 'التالي »',
18 18
 
19 19
 ];
Please login to merge, or discard this patch.
lang/ar/auth.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-    /*
5
+	/*
6 6
     |--------------------------------------------------------------------------
7 7
     | Authentication Language Lines
8 8
     |--------------------------------------------------------------------------
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     |
14 14
     */
15 15
 
16
-    'failed'   => 'بيانات الاعتماد هذه غير متطابقة مع البيانات المسجلة لدينا.',
17
-    'throttle' => 'عدد كبير جدا من محاولات الدخول. يرجى المحاولة مرة أخرى بعد :seconds ثانية.',
16
+	'failed'   => 'بيانات الاعتماد هذه غير متطابقة مع البيانات المسجلة لدينا.',
17
+	'throttle' => 'عدد كبير جدا من محاولات الدخول. يرجى المحاولة مرة أخرى بعد :seconds ثانية.',
18 18
 
19 19
 ];
Please login to merge, or discard this patch.
lang/ar/validation.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-    /*
5
+	/*
6 6
     |--------------------------------------------------------------------------
7 7
     | Validation Language Lines
8 8
     |--------------------------------------------------------------------------
@@ -13,76 +13,76 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 ];
Please login to merge, or discard this patch.
src/Modules/Core/BaseClasses/BaseRepository.php 4 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
      */
Please login to merge, or discard this patch.
Indentation   +551 added lines, -551 removed lines patch added patch discarded remove patch
@@ -8,565 +8,565 @@
 block discarded – undo
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
-    }
76
-
77
-    /**
78
-     * Count all records based on the given condition from storage.
79
-     *
80
-     * @param  array   $conditions array of conditions
81
-     * @return collection
82
-     */
83
-    public function count($conditions)
84
-    {
85
-        $conditions = $this->constructConditions($conditions, $this->model);
86
-        return $this->model->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->count();
87
-    }
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
+
77
+	/**
78
+	 * Count all records based on the given condition from storage.
79
+	 *
80
+	 * @param  array   $conditions array of conditions
81
+	 * @return collection
82
+	 */
83
+	public function count($conditions)
84
+	{
85
+		$conditions = $this->constructConditions($conditions, $this->model);
86
+		return $this->model->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->count();
87
+	}
88 88
     
89
-    /**
90
-     * Save the given model to the storage.
91
-     *
92
-     * @param  array $data
93
-     * @return mixed
94
-     */
95
-    public function save(array $data)
96
-    {
97
-        \Session::put('locale', 'all');
98
-        $model      = false;
99
-        $relations  = [];
100
-
101
-        \DB::transaction(function () use (&$model, &$relations, $data) {
89
+	/**
90
+	 * Save the given model to the storage.
91
+	 *
92
+	 * @param  array $data
93
+	 * @return mixed
94
+	 */
95
+	public function save(array $data)
96
+	{
97
+		\Session::put('locale', 'all');
98
+		$model      = false;
99
+		$relations  = [];
100
+
101
+		\DB::transaction(function () use (&$model, &$relations, $data) {
102 102
             
103
-            $model     = $this->prepareModel($data);
104
-            $relations = $this->prepareRelations($data, $model);
105
-            $model     = $this->saveModel($model, $relations);
106
-        });
103
+			$model     = $this->prepareModel($data);
104
+			$relations = $this->prepareRelations($data, $model);
105
+			$model     = $this->saveModel($model, $relations);
106
+		});
107 107
         
108
-        if (count($relations)) {
109
-            $model->load(...array_keys($relations));
110
-        }
111
-
112
-        return $model;
113
-    }
114
-
115
-    /**
116
-     * Delete record from the storage based on the given
117
-     * condition.
118
-     *
119
-     * @param  var $value condition value
120
-     * @param  string $attribute condition column name
121
-     * @return void
122
-     */
123
-    public function delete($value, $attribute = 'id')
124
-    {
125
-        \DB::transaction(function () use ($value, $attribute) {
126
-            $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) {
127
-                $model->delete();
128
-            });
129
-        });
130
-    }
108
+		if (count($relations)) {
109
+			$model->load(...array_keys($relations));
110
+		}
111
+
112
+		return $model;
113
+	}
114
+
115
+	/**
116
+	 * Delete record from the storage based on the given
117
+	 * condition.
118
+	 *
119
+	 * @param  var $value condition value
120
+	 * @param  string $attribute condition column name
121
+	 * @return void
122
+	 */
123
+	public function delete($value, $attribute = 'id')
124
+	{
125
+		\DB::transaction(function () use ($value, $attribute) {
126
+			$this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) {
127
+				$model->delete();
128
+			});
129
+		});
130
+	}
131 131
     
132
-    /**
133
-     * Fetch records from the storage based on the given
134
-     * id.
135
-     *
136
-     * @param  integer $id
137
-     * @param  string[]   $relations
138
-     * @param  array   $columns
139
-     * @return object
140
-     */
141
-    public function find($id, $relations = [], $columns = ['*'])
142
-    {
143
-        return $this->model->with($relations)->find($id, $columns);
144
-    }
132
+	/**
133
+	 * Fetch records from the storage based on the given
134
+	 * id.
135
+	 *
136
+	 * @param  integer $id
137
+	 * @param  string[]   $relations
138
+	 * @param  array   $columns
139
+	 * @return object
140
+	 */
141
+	public function find($id, $relations = [], $columns = ['*'])
142
+	{
143
+		return $this->model->with($relations)->find($id, $columns);
144
+	}
145 145
     
146
-    /**
147
-     * Fetch records from the storage based on the given
148
-     * condition.
149
-     *
150
-     * @param  array   $conditions array of conditions
151
-     * @param  array   $relations
152
-     * @param  string  $sortBy
153
-     * @param  boolean $desc
154
-     * @param  array   $columns
155
-     * @return collection
156
-     */
157
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
158
-    {
159
-        $conditions = $this->constructConditions($conditions, $this->model);
160
-        $sort       = $desc ? 'desc' : 'asc';
161
-        return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
162
-    }
163
-
164
-    /**
165
-     * Fetch the first record from the storage based on the given
166
-     * condition.
167
-     *
168
-     * @param  array   $conditions array of conditions
169
-     * @param  array   $relations
170
-     * @param  array   $columns
171
-     * @return object
172
-     */
173
-    public function first($conditions, $relations = [], $columns = ['*'])
174
-    {
175
-        $conditions = $this->constructConditions($conditions, $this->model);
176
-        return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);
177
-    }
178
-
179
-    /**
180
-     * Return the deleted models in pages based on the given conditions.
181
-     *
182
-     * @param  array   $conditions array of conditions
183
-     * @param  integer $perPage
184
-     * @param  string  $sortBy
185
-     * @param  boolean $desc
186
-     * @param  array   $columns
187
-     * @return collection
188
-     */
189
-    public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
190
-    {
191
-        unset($conditions['page']);
192
-        unset($conditions['perPage']);
193
-        unset($conditions['sortBy']);
194
-        unset($conditions['sort']);
195
-        $conditions = $this->constructConditions($conditions, $this->model);
196
-        $sort       = $desc ? 'desc' : 'asc';
197
-        $model      = $this->model->onlyTrashed();
198
-
199
-        if (count($conditions['conditionValues'])) {
200
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
201
-        }
202
-
203
-        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
204
-    }
205
-
206
-    /**
207
-     * Restore the deleted model.
208
-     *
209
-     * @param  integer $id
210
-     * @return void
211
-     */
212
-    public function restore($id)
213
-    {
214
-        $model = $this->model->onlyTrashed()->find($id);
215
-
216
-        if (! $model) {
217
-            \Errors::notFound(class_basename($this->model).' with id : '.$id);
218
-        }
219
-
220
-        $model->restore();
221
-    }
222
-
223
-    /**
224
-     * Fill the model with the given data.
225
-     *
226
-     * @param   array  $data
227
-     *
228
-     * @return  object
229
-     */
230
-    public function prepareModel($data)
231
-    {
232
-        $modelClass = $this->model;
233
-
234
-        /**
235
-         * If the id is present in the data then select the model for updating,
236
-         * else create new model.
237
-         * @var array
238
-         */
239
-        $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
240
-        if (! $model) {
241
-            \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']);
242
-        }
243
-
244
-        /**
245
-         * Construct the model object with the given data,
246
-         * and if there is a relation add it to relations array,
247
-         * then save the model.
248
-         */
249
-        foreach ($data as $key => $value) {
250
-            if (array_search($key, $model->getFillable(), true) !== false) {
251
-                /**
252
-                 * If the attribute isn't a relation and prevent attributes not in the fillable.
253
-                 */
254
-                $model->$key = $value;
255
-            }
256
-        }
257
-
258
-        return $model;
259
-    }
146
+	/**
147
+	 * Fetch records from the storage based on the given
148
+	 * condition.
149
+	 *
150
+	 * @param  array   $conditions array of conditions
151
+	 * @param  array   $relations
152
+	 * @param  string  $sortBy
153
+	 * @param  boolean $desc
154
+	 * @param  array   $columns
155
+	 * @return collection
156
+	 */
157
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
158
+	{
159
+		$conditions = $this->constructConditions($conditions, $this->model);
160
+		$sort       = $desc ? 'desc' : 'asc';
161
+		return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
162
+	}
163
+
164
+	/**
165
+	 * Fetch the first record from the storage based on the given
166
+	 * condition.
167
+	 *
168
+	 * @param  array   $conditions array of conditions
169
+	 * @param  array   $relations
170
+	 * @param  array   $columns
171
+	 * @return object
172
+	 */
173
+	public function first($conditions, $relations = [], $columns = ['*'])
174
+	{
175
+		$conditions = $this->constructConditions($conditions, $this->model);
176
+		return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);
177
+	}
178
+
179
+	/**
180
+	 * Return the deleted models in pages based on the given conditions.
181
+	 *
182
+	 * @param  array   $conditions array of conditions
183
+	 * @param  integer $perPage
184
+	 * @param  string  $sortBy
185
+	 * @param  boolean $desc
186
+	 * @param  array   $columns
187
+	 * @return collection
188
+	 */
189
+	public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
190
+	{
191
+		unset($conditions['page']);
192
+		unset($conditions['perPage']);
193
+		unset($conditions['sortBy']);
194
+		unset($conditions['sort']);
195
+		$conditions = $this->constructConditions($conditions, $this->model);
196
+		$sort       = $desc ? 'desc' : 'asc';
197
+		$model      = $this->model->onlyTrashed();
198
+
199
+		if (count($conditions['conditionValues'])) {
200
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
201
+		}
202
+
203
+		return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
204
+	}
205
+
206
+	/**
207
+	 * Restore the deleted model.
208
+	 *
209
+	 * @param  integer $id
210
+	 * @return void
211
+	 */
212
+	public function restore($id)
213
+	{
214
+		$model = $this->model->onlyTrashed()->find($id);
215
+
216
+		if (! $model) {
217
+			\Errors::notFound(class_basename($this->model).' with id : '.$id);
218
+		}
219
+
220
+		$model->restore();
221
+	}
222
+
223
+	/**
224
+	 * Fill the model with the given data.
225
+	 *
226
+	 * @param   array  $data
227
+	 *
228
+	 * @return  object
229
+	 */
230
+	public function prepareModel($data)
231
+	{
232
+		$modelClass = $this->model;
233
+
234
+		/**
235
+		 * If the id is present in the data then select the model for updating,
236
+		 * else create new model.
237
+		 * @var array
238
+		 */
239
+		$model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
240
+		if (! $model) {
241
+			\Errors::notFound(class_basename($modelClass).' with id : '.$data['id']);
242
+		}
243
+
244
+		/**
245
+		 * Construct the model object with the given data,
246
+		 * and if there is a relation add it to relations array,
247
+		 * then save the model.
248
+		 */
249
+		foreach ($data as $key => $value) {
250
+			if (array_search($key, $model->getFillable(), true) !== false) {
251
+				/**
252
+				 * If the attribute isn't a relation and prevent attributes not in the fillable.
253
+				 */
254
+				$model->$key = $value;
255
+			}
256
+		}
257
+
258
+		return $model;
259
+	}
260 260
     
261
-    /**
262
-     * Prepare related models based on the given data for the given model.
263
-     *
264
-     * @param   array  $data
265
-     * @param   object $model
266
-     *
267
-     * @return  array
268
-     */
269
-    public function prepareRelations($data, $model)
270
-    {
271
-        /**
272
-         * Init the relation array
273
-         *
274
-         * @var array
275
-         */
276
-        $relations = [];
277
-
278
-        /**
279
-         * Construct the model object with the given data,
280
-         * and if there is a relation add it to relations array,
281
-         * then save the model.
282
-         */
283
-        foreach ($data as $key => $value) {
284
-            /**
285
-             * If the attribute is a relation.
286
-             */
287
-            $relation = \Str::camel($key);
288
-            if (method_exists($model, $relation) && \Core::$relation()) {
289
-                /**
290
-                 * Check if the relation is a collection.
291
-                 */
292
-                if (class_basename($model->$relation) == 'Collection') {
293
-                    /**
294
-                     * If the relation has no value then marke the relation data
295
-                     * related to the model to be deleted.
296
-                     */
297
-                    if (! $value || ! count($value)) {
298
-                        $relations[$relation] = 'delete';
299
-                    }
300
-                }
301
-                if (is_array($value)) {
302
-                    /**
303
-                     * Loop through the relation data.
304
-                     */
305
-                    foreach ($value as $attr => $val) {
306
-                        /**
307
-                         * Get the relation model.
308
-                         */
309
-                        $relationBaseModel = \Core::$relation()->model;
310
-
311
-                        /**
312
-                         * Check if the relation is a collection.
313
-                         */
314
-                        if (class_basename($model->$relation) == 'Collection') {
315
-                            /**
316
-                             * If the id is present in the data then select the relation model for updating,
317
-                             * else create new model.
318
-                             */
319
-                            $relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
320
-
321
-                            /**
322
-                             * If model doesn't exists.
323
-                             */
324
-                            if (! $relationModel) {
325
-                                \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
326
-                            }
327
-
328
-                            /**
329
-                             * Loop through the relation attributes.
330
-                             */
331
-                            foreach ($val as $attr => $val) {
332
-                                /**
333
-                                 * Prevent the sub relations or attributes not in the fillable.
334
-                                 */
335
-                                if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) {
336
-                                    $relationModel->$attr = $val;
337
-                                } elseif(gettype($val) !== 'object' && gettype($val) !== 'array' && $attr !== 'id') {
338
-                                    $extra[$attr] = $val;
339
-                                }
340
-                            }
341
-
342
-                            if(isset($extra)) $relationModel->extra = $extra;
343
-                            $relations[$relation][] = $relationModel;
344
-                        } else {
345
-                            /**
346
-                             * Prevent the sub relations.
347
-                             */
348
-                            if (gettype($val) !== 'object' && gettype($val) !== 'array') {
349
-                                /**
350
-                                 * If the id is present in the data then select the relation model for updating,
351
-                                 * else create new model.
352
-                                 */
353
-                                $relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
354
-
355
-                                /**
356
-                                 * If model doesn't exists.
357
-                                 */
358
-                                if (! $relationModel) {
359
-                                    \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
360
-                                }
361
-
362
-                                foreach ($value as $relationAttribute => $relationValue) {
363
-                                    /**
364
-                                     * Prevent attributes not in the fillable.
365
-                                     */
366
-                                    if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) {
367
-                                        $relationModel->$relationAttribute = $relationValue;
368
-                                    }
369
-                                }
370
-
371
-                                $relations[$relation] = $relationModel;
372
-                            }
373
-                        }
374
-                    }
375
-                }
376
-            }
377
-        }
378
-
379
-        return $relations;
380
-    }
381
-
382
-    /**
383
-     * Save the model with related models.
384
-     *
385
-     * @param   object  $model
386
-     * @param   array   $relations
387
-     *
388
-     * @return  object
389
-     */
390
-    public function saveModel($model, $relations)
391
-    {
392
-
393
-        /**
394
-         * Loop through the relations array.
395
-         */
396
-        foreach ($relations as $key => $value) {
397
-            /**
398
-             * If the relation is marked for delete then delete it.
399
-             */
400
-            if ($value == 'delete' && $model->$key()->count()) {
401
-                $model->$key()->delete();
402
-            } elseif (gettype($value) == 'array') {
403
-                /**
404
-                 * Save the model.
405
-                 */
406
-                $model->save();
407
-                $ids = [];
408
-
409
-                /**
410
-                 * Loop through the relations.
411
-                 */
412
-                foreach ($value as $val) {
413
-                    switch (class_basename($model->$key())) {
414
-                        /**
415
-                         * If the relation is one to many then update it's foreign key with
416
-                         * the model id and save it then add its id to ids array to delete all
417
-                         * relations who's id isn't in the ids array.
418
-                         */
419
-                        case 'HasMany':
420
-                            $foreignKeyName       = $model->$key()->getForeignKeyName();
421
-                            $val->$foreignKeyName = $model->id;
422
-                            $val->save();
423
-                            $ids[] = $val->id;
424
-                            break;
425
-
426
-                        /**
427
-                         * If the relation is many to many then add it's id to the ids array to
428
-                         * attache these ids to the model.
429
-                         */
430
-                        case 'BelongsToMany':
431
-                            $extra = $val->extra;
432
-                            unset($val->extra);
433
-                            $val->save();
434
-                            $ids[$val->id] = $extra ?? [];
435
-                            break;
436
-                    }
437
-                }
438
-                switch (class_basename($model->$key())) {
439
-                    /**
440
-                     * If the relation is one to many then delete all
441
-                     * relations who's id isn't in the ids array.
442
-                     */
443
-                    case 'HasMany':
444
-                        $model->$key()->whereNotIn('id', $ids)->delete();
445
-                        break;
446
-
447
-                    /**
448
-                     * If the relation is many to many then
449
-                     * detach the previous data and attach
450
-                     * the ids array to the model.
451
-                     */
452
-                    case 'BelongsToMany':
453
-                        $model->$key()->detach();
454
-                        $model->$key()->attach($ids);
455
-                        break;
456
-                }
457
-            } else {
458
-                switch (class_basename($model->$key())) {
459
-                    /**
460
-                     * If the relation is one to one.
461
-                     */
462
-                    case 'HasOne':
463
-                        /**
464
-                         * Save the model.
465
-                         */
466
-                        $model->save();
467
-                        $foreignKeyName         = $model->$key()->getForeignKeyName();
468
-                        $value->$foreignKeyName = $model->id;
469
-                        $value->save();
470
-                        break;
471
-                    case 'BelongsTo':
472
-                        /**
473
-                         * Save the model.
474
-                         */
475
-                        $value->save();
476
-                        $model->$key()->associate($value);
477
-                        break;
478
-                }
479
-            }
480
-        }
481
-
482
-        /**
483
-         * Save the model.
484
-         */
485
-        $model->save();
486
-
487
-        return $model;
488
-    }
489
-
490
-    /**
491
-     * Build the conditions recursively for the retrieving methods.
492
-     * @param  array $conditions
493
-     * @return array
494
-     */
495
-    protected function constructConditions($conditions, $model)
496
-    {
497
-        $conditionString = '';
498
-        $conditionValues = [];
499
-        foreach ($conditions as $key => $value) {
500
-            if (Str::contains($key, '->')) {
501
-                $key = $this->wrapJsonSelector($key);
502
-            }
503
-
504
-            if ($key == 'and') {
505
-                $conditions       = $this->constructConditions($value, $model);
506
-                $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} ';
507
-                $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
508
-            } elseif ($key == 'or') {
509
-                $conditions       = $this->constructConditions($value, $model);
510
-                $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} ';
511
-                $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
512
-            } else {
513
-                if (is_array($value)) {
514
-                    $operator = $value['op'];
515
-                    if (strtolower($operator) == 'between') {
516
-                        $value1 = $value['val1'];
517
-                        $value2 = $value['val2'];
518
-                    } else {
519
-                        $value = Arr::get($value, 'val', '');
520
-                    }
521
-                } else {
522
-                    $operator = '=';
523
-                }
261
+	/**
262
+	 * Prepare related models based on the given data for the given model.
263
+	 *
264
+	 * @param   array  $data
265
+	 * @param   object $model
266
+	 *
267
+	 * @return  array
268
+	 */
269
+	public function prepareRelations($data, $model)
270
+	{
271
+		/**
272
+		 * Init the relation array
273
+		 *
274
+		 * @var array
275
+		 */
276
+		$relations = [];
277
+
278
+		/**
279
+		 * Construct the model object with the given data,
280
+		 * and if there is a relation add it to relations array,
281
+		 * then save the model.
282
+		 */
283
+		foreach ($data as $key => $value) {
284
+			/**
285
+			 * If the attribute is a relation.
286
+			 */
287
+			$relation = \Str::camel($key);
288
+			if (method_exists($model, $relation) && \Core::$relation()) {
289
+				/**
290
+				 * Check if the relation is a collection.
291
+				 */
292
+				if (class_basename($model->$relation) == 'Collection') {
293
+					/**
294
+					 * If the relation has no value then marke the relation data
295
+					 * related to the model to be deleted.
296
+					 */
297
+					if (! $value || ! count($value)) {
298
+						$relations[$relation] = 'delete';
299
+					}
300
+				}
301
+				if (is_array($value)) {
302
+					/**
303
+					 * Loop through the relation data.
304
+					 */
305
+					foreach ($value as $attr => $val) {
306
+						/**
307
+						 * Get the relation model.
308
+						 */
309
+						$relationBaseModel = \Core::$relation()->model;
310
+
311
+						/**
312
+						 * Check if the relation is a collection.
313
+						 */
314
+						if (class_basename($model->$relation) == 'Collection') {
315
+							/**
316
+							 * If the id is present in the data then select the relation model for updating,
317
+							 * else create new model.
318
+							 */
319
+							$relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
320
+
321
+							/**
322
+							 * If model doesn't exists.
323
+							 */
324
+							if (! $relationModel) {
325
+								\Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
326
+							}
327
+
328
+							/**
329
+							 * Loop through the relation attributes.
330
+							 */
331
+							foreach ($val as $attr => $val) {
332
+								/**
333
+								 * Prevent the sub relations or attributes not in the fillable.
334
+								 */
335
+								if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) {
336
+									$relationModel->$attr = $val;
337
+								} elseif(gettype($val) !== 'object' && gettype($val) !== 'array' && $attr !== 'id') {
338
+									$extra[$attr] = $val;
339
+								}
340
+							}
341
+
342
+							if(isset($extra)) $relationModel->extra = $extra;
343
+							$relations[$relation][] = $relationModel;
344
+						} else {
345
+							/**
346
+							 * Prevent the sub relations.
347
+							 */
348
+							if (gettype($val) !== 'object' && gettype($val) !== 'array') {
349
+								/**
350
+								 * If the id is present in the data then select the relation model for updating,
351
+								 * else create new model.
352
+								 */
353
+								$relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
354
+
355
+								/**
356
+								 * If model doesn't exists.
357
+								 */
358
+								if (! $relationModel) {
359
+									\Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
360
+								}
361
+
362
+								foreach ($value as $relationAttribute => $relationValue) {
363
+									/**
364
+									 * Prevent attributes not in the fillable.
365
+									 */
366
+									if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) {
367
+										$relationModel->$relationAttribute = $relationValue;
368
+									}
369
+								}
370
+
371
+								$relations[$relation] = $relationModel;
372
+							}
373
+						}
374
+					}
375
+				}
376
+			}
377
+		}
378
+
379
+		return $relations;
380
+	}
381
+
382
+	/**
383
+	 * Save the model with related models.
384
+	 *
385
+	 * @param   object  $model
386
+	 * @param   array   $relations
387
+	 *
388
+	 * @return  object
389
+	 */
390
+	public function saveModel($model, $relations)
391
+	{
392
+
393
+		/**
394
+		 * Loop through the relations array.
395
+		 */
396
+		foreach ($relations as $key => $value) {
397
+			/**
398
+			 * If the relation is marked for delete then delete it.
399
+			 */
400
+			if ($value == 'delete' && $model->$key()->count()) {
401
+				$model->$key()->delete();
402
+			} elseif (gettype($value) == 'array') {
403
+				/**
404
+				 * Save the model.
405
+				 */
406
+				$model->save();
407
+				$ids = [];
408
+
409
+				/**
410
+				 * Loop through the relations.
411
+				 */
412
+				foreach ($value as $val) {
413
+					switch (class_basename($model->$key())) {
414
+						/**
415
+						 * If the relation is one to many then update it's foreign key with
416
+						 * the model id and save it then add its id to ids array to delete all
417
+						 * relations who's id isn't in the ids array.
418
+						 */
419
+						case 'HasMany':
420
+							$foreignKeyName       = $model->$key()->getForeignKeyName();
421
+							$val->$foreignKeyName = $model->id;
422
+							$val->save();
423
+							$ids[] = $val->id;
424
+							break;
425
+
426
+						/**
427
+						 * If the relation is many to many then add it's id to the ids array to
428
+						 * attache these ids to the model.
429
+						 */
430
+						case 'BelongsToMany':
431
+							$extra = $val->extra;
432
+							unset($val->extra);
433
+							$val->save();
434
+							$ids[$val->id] = $extra ?? [];
435
+							break;
436
+					}
437
+				}
438
+				switch (class_basename($model->$key())) {
439
+					/**
440
+					 * If the relation is one to many then delete all
441
+					 * relations who's id isn't in the ids array.
442
+					 */
443
+					case 'HasMany':
444
+						$model->$key()->whereNotIn('id', $ids)->delete();
445
+						break;
446
+
447
+					/**
448
+					 * If the relation is many to many then
449
+					 * detach the previous data and attach
450
+					 * the ids array to the model.
451
+					 */
452
+					case 'BelongsToMany':
453
+						$model->$key()->detach();
454
+						$model->$key()->attach($ids);
455
+						break;
456
+				}
457
+			} else {
458
+				switch (class_basename($model->$key())) {
459
+					/**
460
+					 * If the relation is one to one.
461
+					 */
462
+					case 'HasOne':
463
+						/**
464
+						 * Save the model.
465
+						 */
466
+						$model->save();
467
+						$foreignKeyName         = $model->$key()->getForeignKeyName();
468
+						$value->$foreignKeyName = $model->id;
469
+						$value->save();
470
+						break;
471
+					case 'BelongsTo':
472
+						/**
473
+						 * Save the model.
474
+						 */
475
+						$value->save();
476
+						$model->$key()->associate($value);
477
+						break;
478
+				}
479
+			}
480
+		}
481
+
482
+		/**
483
+		 * Save the model.
484
+		 */
485
+		$model->save();
486
+
487
+		return $model;
488
+	}
489
+
490
+	/**
491
+	 * Build the conditions recursively for the retrieving methods.
492
+	 * @param  array $conditions
493
+	 * @return array
494
+	 */
495
+	protected function constructConditions($conditions, $model)
496
+	{
497
+		$conditionString = '';
498
+		$conditionValues = [];
499
+		foreach ($conditions as $key => $value) {
500
+			if (Str::contains($key, '->')) {
501
+				$key = $this->wrapJsonSelector($key);
502
+			}
503
+
504
+			if ($key == 'and') {
505
+				$conditions       = $this->constructConditions($value, $model);
506
+				$conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} ';
507
+				$conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
508
+			} elseif ($key == 'or') {
509
+				$conditions       = $this->constructConditions($value, $model);
510
+				$conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} ';
511
+				$conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
512
+			} else {
513
+				if (is_array($value)) {
514
+					$operator = $value['op'];
515
+					if (strtolower($operator) == 'between') {
516
+						$value1 = $value['val1'];
517
+						$value2 = $value['val2'];
518
+					} else {
519
+						$value = Arr::get($value, 'val', '');
520
+					}
521
+				} else {
522
+					$operator = '=';
523
+				}
524 524
                 
525
-                if (strtolower($operator) == 'between') {
526
-                    $conditionString  .= $key.' >= ? and ';
527
-                    $conditionValues[] = $value1;
528
-
529
-                    $conditionString  .= $key.' <= ? {op} ';
530
-                    $conditionValues[] = $value2;
531
-                } elseif (strtolower($operator) == 'in') {
532
-                    $conditionValues  = array_merge($conditionValues, $value);
533
-                    $inBindingsString = rtrim(str_repeat('?,', count($value)), ',');
534
-                    $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} ';
535
-                } elseif (strtolower($operator) == 'null') {
536
-                    $conditionString .= $key.' is null {op} ';
537
-                } elseif (strtolower($operator) == 'not null') {
538
-                    $conditionString .= $key.' is not null {op} ';
539
-                } elseif (strtolower($operator) == 'has') {
540
-                    $sql              = $model->withTrashed()->has($key)->toSql();
541
-                    $conditions       = $this->constructConditions($value, $model->$key()->getRelated());
542
-                    $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} ';
543
-                    $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
544
-                } else {
545
-                    $conditionString  .= $key.' '.$operator.' ? {op} ';
546
-                    $conditionValues[] = $value;
547
-                }
548
-            }
549
-        }
550
-        $conditionString = '('.rtrim($conditionString, '{op} ').')';
551
-        return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
552
-    }
553
-
554
-    /**
555
-     * Wrap the given JSON selector.
556
-     *
557
-     * @param  string  $value
558
-     * @return string
559
-     */
560
-    protected function wrapJsonSelector($value)
561
-    {
562
-        $removeLast = strpos($value, ')');
563
-        $value      = $removeLast === false ? $value : substr($value, 0, $removeLast);
564
-        $path       = explode('->', $value);
565
-        $field      = array_shift($path);
566
-        $result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) {
567
-            return '"'.$part.'"';
568
-        })->implode('.'));
525
+				if (strtolower($operator) == 'between') {
526
+					$conditionString  .= $key.' >= ? and ';
527
+					$conditionValues[] = $value1;
528
+
529
+					$conditionString  .= $key.' <= ? {op} ';
530
+					$conditionValues[] = $value2;
531
+				} elseif (strtolower($operator) == 'in') {
532
+					$conditionValues  = array_merge($conditionValues, $value);
533
+					$inBindingsString = rtrim(str_repeat('?,', count($value)), ',');
534
+					$conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} ';
535
+				} elseif (strtolower($operator) == 'null') {
536
+					$conditionString .= $key.' is null {op} ';
537
+				} elseif (strtolower($operator) == 'not null') {
538
+					$conditionString .= $key.' is not null {op} ';
539
+				} elseif (strtolower($operator) == 'has') {
540
+					$sql              = $model->withTrashed()->has($key)->toSql();
541
+					$conditions       = $this->constructConditions($value, $model->$key()->getRelated());
542
+					$conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} ';
543
+					$conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
544
+				} else {
545
+					$conditionString  .= $key.' '.$operator.' ? {op} ';
546
+					$conditionValues[] = $value;
547
+				}
548
+			}
549
+		}
550
+		$conditionString = '('.rtrim($conditionString, '{op} ').')';
551
+		return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
552
+	}
553
+
554
+	/**
555
+	 * Wrap the given JSON selector.
556
+	 *
557
+	 * @param  string  $value
558
+	 * @return string
559
+	 */
560
+	protected function wrapJsonSelector($value)
561
+	{
562
+		$removeLast = strpos($value, ')');
563
+		$value      = $removeLast === false ? $value : substr($value, 0, $removeLast);
564
+		$path       = explode('->', $value);
565
+		$field      = array_shift($path);
566
+		$result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) {
567
+			return '"'.$part.'"';
568
+		})->implode('.'));
569 569
         
570
-        return $removeLast === false ? $result : $result.')';
571
-    }
570
+		return $removeLast === false ? $result : $result.')';
571
+	}
572 572
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      */
22 22
     public function __construct($model)
23 23
     {
24
-        $this->model  = $model;
24
+        $this->model = $model;
25 25
     }
26 26
 
27 27
     /**
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
         $model      = false;
99 99
         $relations  = [];
100 100
 
101
-        \DB::transaction(function () use (&$model, &$relations, $data) {
101
+        \DB::transaction(function() use (&$model, &$relations, $data) {
102 102
             
103 103
             $model     = $this->prepareModel($data);
104 104
             $relations = $this->prepareRelations($data, $model);
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function delete($value, $attribute = 'id')
124 124
     {
125
-        \DB::transaction(function () use ($value, $attribute) {
126
-            $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) {
125
+        \DB::transaction(function() use ($value, $attribute) {
126
+            $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function($model) {
127 127
                 $model->delete();
128 128
             });
129 129
         });
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     {
214 214
         $model = $this->model->onlyTrashed()->find($id);
215 215
 
216
-        if (! $model) {
216
+        if ( ! $model) {
217 217
             \Errors::notFound(class_basename($this->model).' with id : '.$id);
218 218
         }
219 219
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
          * @var array
238 238
          */
239 239
         $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
240
-        if (! $model) {
240
+        if ( ! $model) {
241 241
             \Errors::notFound(class_basename($modelClass).' with id : '.$data['id']);
242 242
         }
243 243
 
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
                      * If the relation has no value then marke the relation data
295 295
                      * related to the model to be deleted.
296 296
                      */
297
-                    if (! $value || ! count($value)) {
297
+                    if ( ! $value || ! count($value)) {
298 298
                         $relations[$relation] = 'delete';
299 299
                     }
300 300
                 }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
                             /**
322 322
                              * If model doesn't exists.
323 323
                              */
324
-                            if (! $relationModel) {
324
+                            if ( ! $relationModel) {
325 325
                                 \Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
326 326
                             }
327 327
 
@@ -334,12 +334,12 @@  discard block
 block discarded – undo
334 334
                                  */
335 335
                                 if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) {
336 336
                                     $relationModel->$attr = $val;
337
-                                } elseif(gettype($val) !== 'object' && gettype($val) !== 'array' && $attr !== 'id') {
337
+                                } elseif (gettype($val) !== 'object' && gettype($val) !== 'array' && $attr !== 'id') {
338 338
                                     $extra[$attr] = $val;
339 339
                                 }
340 340
                             }
341 341
 
342
-                            if(isset($extra)) $relationModel->extra = $extra;
342
+                            if (isset($extra)) $relationModel->extra = $extra;
343 343
                             $relations[$relation][] = $relationModel;
344 344
                         } else {
345 345
                             /**
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
                                 /**
356 356
                                  * If model doesn't exists.
357 357
                                  */
358
-                                if (! $relationModel) {
358
+                                if ( ! $relationModel) {
359 359
                                     \Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
360 360
                                 }
361 361
 
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
         $value      = $removeLast === false ? $value : substr($value, 0, $removeLast);
564 564
         $path       = explode('->', $value);
565 565
         $field      = array_shift($path);
566
-        $result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) {
566
+        $result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function($part) {
567 567
             return '"'.$part.'"';
568 568
         })->implode('.'));
569 569
         
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -339,7 +339,9 @@
 block discarded – undo
339 339
                                 }
340 340
                             }
341 341
 
342
-                            if(isset($extra)) $relationModel->extra = $extra;
342
+                            if(isset($extra)) {
343
+                            	$relationModel->extra = $extra;
344
+                            }
343 345
                             $relations[$relation][] = $relationModel;
344 346
                         } else {
345 347
                             /**
Please login to merge, or discard this patch.
src/Modules/Core/BaseClasses/BaseService.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @param  array   $relations
54 54
      * @param  string  $sortBy
55
-     * @param  boolean $desc
55
+     * @param  integer $desc
56 56
      * @param  array   $columns
57 57
      * @return collection
58 58
      */
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      * @param  integer $perPage
68 68
      * @param  array   $relations
69 69
      * @param  string  $sortBy
70
-     * @param  boolean $desc
70
+     * @param  integer $desc
71 71
      * @param  array   $columns
72 72
      * @return collection
73 73
      */
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @param  integer $perPage
85 85
      * @param  array   $relations
86 86
      * @param  string  $sortBy
87
-     * @param  boolean $desc
87
+     * @param  integer $desc
88 88
      * @param  array   $columns
89 89
      * @return collection
90 90
      */
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @param  array   $conditions array of conditions
139 139
      * @param  array   $relations
140 140
      * @param  string  $sortBy
141
-     * @param  boolean $desc
141
+     * @param  integer $desc
142 142
      * @param  array   $columns
143 143
      * @return collection
144 144
      */
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
      * @param  array   $conditions array of conditions
168 168
      * @param  integer $perPage
169 169
      * @param  string  $sortBy
170
-     * @param  boolean $desc
170
+     * @param  integer $desc
171 171
      * @param  array   $columns
172 172
      * @return collection
173 173
      */
Please login to merge, or discard this patch.
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -6,194 +6,194 @@
 block discarded – undo
6 6
 
7 7
 abstract class BaseService implements BaseServiceInterface
8 8
 {
9
-    /**
10
-     * @var object
11
-     */
12
-    public $repo;
9
+	/**
10
+	 * @var object
11
+	 */
12
+	public $repo;
13 13
 
14
-    /**
15
-     * Init new object.
16
-     *
17
-     * @param   mixed  $repo
18
-     * @return  void
19
-     */
20
-    public function __construct($repo)
21
-    {
22
-        $this->repo = $repo;
23
-    }
14
+	/**
15
+	 * Init new object.
16
+	 *
17
+	 * @param   mixed  $repo
18
+	 * @return  void
19
+	 */
20
+	public function __construct($repo)
21
+	{
22
+		$this->repo = $repo;
23
+	}
24 24
 
25
-    /**
26
-     * Fetch records with relations based on the given params.
27
-     *
28
-     * @param   array   $relations
29
-     * @param   array   $conditions
30
-     * @param   integer $perPage
31
-     * @param   string  $sortBy
32
-     * @param   boolean $desc
33
-     * @param   boolean $trashed
34
-     * @return collection
35
-     */
36
-    public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true, $trashed = false)
37
-    {
38
-        $filters = [];
39
-        $translatable = $this->repo->model->translatable ?? [];
40
-        foreach ($conditions as $key => $value) {
41
-            if($value && in_array($key, $this->repo->model->fillable ?? [])) {
42
-                $key = in_array($key, $translatable) ? $key . '->' . (\Session::get('locale') == 'all' ? 'en' : \Session::get('locale')) : $key;
43
-                $isBool = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null;
44
-                $filters[$key] = $isBool ? filter_var($value, FILTER_VALIDATE_BOOLEAN) : $value;
45
-            }
46
-        }
47
-        $sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . \Session::get('locale') : $sortBy;
25
+	/**
26
+	 * Fetch records with relations based on the given params.
27
+	 *
28
+	 * @param   array   $relations
29
+	 * @param   array   $conditions
30
+	 * @param   integer $perPage
31
+	 * @param   string  $sortBy
32
+	 * @param   boolean $desc
33
+	 * @param   boolean $trashed
34
+	 * @return collection
35
+	 */
36
+	public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true, $trashed = false)
37
+	{
38
+		$filters = [];
39
+		$translatable = $this->repo->model->translatable ?? [];
40
+		foreach ($conditions as $key => $value) {
41
+			if($value && in_array($key, $this->repo->model->fillable ?? [])) {
42
+				$key = in_array($key, $translatable) ? $key . '->' . (\Session::get('locale') == 'all' ? 'en' : \Session::get('locale')) : $key;
43
+				$isBool = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null;
44
+				$filters[$key] = $isBool ? filter_var($value, FILTER_VALIDATE_BOOLEAN) : $value;
45
+			}
46
+		}
47
+		$sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . \Session::get('locale') : $sortBy;
48 48
 
49
-        if ($trashed) {
50
-            return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true);
51
-        }
49
+		if ($trashed) {
50
+			return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true);
51
+		}
52 52
         
53
-        if (count($filters)) {
54
-            return $this->paginateBy(['and' => $filters], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
55
-        }
53
+		if (count($filters)) {
54
+			return $this->paginateBy(['and' => $filters], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
55
+		}
56 56
 
57
-        return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
58
-    }
57
+		return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
58
+	}
59 59
 
60
-    /**
61
-     * Fetch all records with relations from the storage.
62
-     *
63
-     * @param  array   $relations
64
-     * @param  string  $sortBy
65
-     * @param  boolean $desc
66
-     * @param  array   $columns
67
-     * @return collection
68
-     */
69
-    public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
70
-    {
71
-        return $this->repo->all($relations, $sortBy, $desc, $columns);
72
-    }
60
+	/**
61
+	 * Fetch all records with relations from the storage.
62
+	 *
63
+	 * @param  array   $relations
64
+	 * @param  string  $sortBy
65
+	 * @param  boolean $desc
66
+	 * @param  array   $columns
67
+	 * @return collection
68
+	 */
69
+	public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
70
+	{
71
+		return $this->repo->all($relations, $sortBy, $desc, $columns);
72
+	}
73 73
     
74
-    /**
75
-     * Fetch all records with relations from storage in pages.
76
-     *
77
-     * @param  integer $perPage
78
-     * @param  array   $relations
79
-     * @param  string  $sortBy
80
-     * @param  boolean $desc
81
-     * @param  array   $columns
82
-     * @return collection
83
-     */
84
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
85
-    {
86
-        return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns);
87
-    }
74
+	/**
75
+	 * Fetch all records with relations from storage in pages.
76
+	 *
77
+	 * @param  integer $perPage
78
+	 * @param  array   $relations
79
+	 * @param  string  $sortBy
80
+	 * @param  boolean $desc
81
+	 * @param  array   $columns
82
+	 * @return collection
83
+	 */
84
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
85
+	{
86
+		return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns);
87
+	}
88 88
 
89
-    /**
90
-     * Fetch all records with relations based on
91
-     * the given condition from storage in pages.
92
-     *
93
-     * @param  array   $conditions array of conditions
94
-     * @param  integer $perPage
95
-     * @param  array   $relations
96
-     * @param  string  $sortBy
97
-     * @param  boolean $desc
98
-     * @param  array   $columns
99
-     * @return collection
100
-     */
101
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
102
-    {
103
-        return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns);
104
-    }
89
+	/**
90
+	 * Fetch all records with relations based on
91
+	 * the given condition from storage in pages.
92
+	 *
93
+	 * @param  array   $conditions array of conditions
94
+	 * @param  integer $perPage
95
+	 * @param  array   $relations
96
+	 * @param  string  $sortBy
97
+	 * @param  boolean $desc
98
+	 * @param  array   $columns
99
+	 * @return collection
100
+	 */
101
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
102
+	{
103
+		return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns);
104
+	}
105 105
     
106
-    /**
107
-     * Save the given model to the storage.
108
-     *
109
-     * @param  array $data
110
-     * @return mixed
111
-     */
112
-    public function save(array $data)
113
-    {
114
-        return $this->repo->save($data);
115
-    }
106
+	/**
107
+	 * Save the given model to the storage.
108
+	 *
109
+	 * @param  array $data
110
+	 * @return mixed
111
+	 */
112
+	public function save(array $data)
113
+	{
114
+		return $this->repo->save($data);
115
+	}
116 116
 
117
-    /**
118
-     * Delete record from the storage based on the given
119
-     * condition.
120
-     *
121
-     * @param  var $value condition value
122
-     * @param  string $attribute condition column name
123
-     * @return void
124
-     */
125
-    public function delete($value, $attribute = 'id')
126
-    {
127
-        return $this->repo->delete($value, $attribute);
128
-    }
117
+	/**
118
+	 * Delete record from the storage based on the given
119
+	 * condition.
120
+	 *
121
+	 * @param  var $value condition value
122
+	 * @param  string $attribute condition column name
123
+	 * @return void
124
+	 */
125
+	public function delete($value, $attribute = 'id')
126
+	{
127
+		return $this->repo->delete($value, $attribute);
128
+	}
129 129
     
130
-    /**
131
-     * Fetch records from the storage based on the given
132
-     * id.
133
-     *
134
-     * @param  integer $id
135
-     * @param  array   $relations
136
-     * @param  array   $columns
137
-     * @return object
138
-     */
139
-    public function find($id, $relations = [], $columns = ['*'])
140
-    {
141
-        return $this->repo->find($id, $relations, $columns);
142
-    }
130
+	/**
131
+	 * Fetch records from the storage based on the given
132
+	 * id.
133
+	 *
134
+	 * @param  integer $id
135
+	 * @param  array   $relations
136
+	 * @param  array   $columns
137
+	 * @return object
138
+	 */
139
+	public function find($id, $relations = [], $columns = ['*'])
140
+	{
141
+		return $this->repo->find($id, $relations, $columns);
142
+	}
143 143
     
144
-    /**
145
-     * Fetch records from the storage based on the given
146
-     * condition.
147
-     *
148
-     * @param  array   $conditions array of conditions
149
-     * @param  array   $relations
150
-     * @param  string  $sortBy
151
-     * @param  boolean $desc
152
-     * @param  array   $columns
153
-     * @return collection
154
-     */
155
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
156
-    {
157
-        return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns);
158
-    }
144
+	/**
145
+	 * Fetch records from the storage based on the given
146
+	 * condition.
147
+	 *
148
+	 * @param  array   $conditions array of conditions
149
+	 * @param  array   $relations
150
+	 * @param  string  $sortBy
151
+	 * @param  boolean $desc
152
+	 * @param  array   $columns
153
+	 * @return collection
154
+	 */
155
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
156
+	{
157
+		return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns);
158
+	}
159 159
 
160
-    /**
161
-     * Fetch the first record from the storage based on the given
162
-     * condition.
163
-     *
164
-     * @param  array   $conditions array of conditions
165
-     * @param  array   $relations
166
-     * @param  array   $columns
167
-     * @return object
168
-     */
169
-    public function first($conditions, $relations = [], $columns = ['*'])
170
-    {
171
-        return $this->repo->first($conditions, $relations, $columns);
172
-    }
160
+	/**
161
+	 * Fetch the first record from the storage based on the given
162
+	 * condition.
163
+	 *
164
+	 * @param  array   $conditions array of conditions
165
+	 * @param  array   $relations
166
+	 * @param  array   $columns
167
+	 * @return object
168
+	 */
169
+	public function first($conditions, $relations = [], $columns = ['*'])
170
+	{
171
+		return $this->repo->first($conditions, $relations, $columns);
172
+	}
173 173
 
174
-    /**
175
-     * Return the deleted models in pages based on the given conditions.
176
-     *
177
-     * @param  array   $conditions array of conditions
178
-     * @param  integer $perPage
179
-     * @param  string  $sortBy
180
-     * @param  boolean $desc
181
-     * @param  array   $columns
182
-     * @return collection
183
-     */
184
-    public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
185
-    {
186
-        return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns);
187
-    }
174
+	/**
175
+	 * Return the deleted models in pages based on the given conditions.
176
+	 *
177
+	 * @param  array   $conditions array of conditions
178
+	 * @param  integer $perPage
179
+	 * @param  string  $sortBy
180
+	 * @param  boolean $desc
181
+	 * @param  array   $columns
182
+	 * @return collection
183
+	 */
184
+	public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
185
+	{
186
+		return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns);
187
+	}
188 188
 
189
-    /**
190
-     * Restore the deleted model.
191
-     *
192
-     * @param  integer $id
193
-     * @return void
194
-     */
195
-    public function restore($id)
196
-    {
197
-        return $this->repo->restore($id);
198
-    }
189
+	/**
190
+	 * Restore the deleted model.
191
+	 *
192
+	 * @param  integer $id
193
+	 * @return void
194
+	 */
195
+	public function restore($id)
196
+	{
197
+		return $this->repo->restore($id);
198
+	}
199 199
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
38 38
         $filters = [];
39 39
         $translatable = $this->repo->model->translatable ?? [];
40 40
         foreach ($conditions as $key => $value) {
41
-            if($value && in_array($key, $this->repo->model->fillable ?? [])) {
42
-                $key = in_array($key, $translatable) ? $key . '->' . (\Session::get('locale') == 'all' ? 'en' : \Session::get('locale')) : $key;
41
+            if ($value && in_array($key, $this->repo->model->fillable ?? [])) {
42
+                $key = in_array($key, $translatable) ? $key.'->'.(\Session::get('locale') == 'all' ? 'en' : \Session::get('locale')) : $key;
43 43
                 $isBool = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null;
44 44
                 $filters[$key] = $isBool ? filter_var($value, FILTER_VALIDATE_BOOLEAN) : $value;
45 45
             }
46 46
         }
47
-        $sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . \Session::get('locale') : $sortBy;
47
+        $sortBy = in_array($sortBy, $translatable) ? $sortBy.'->'.\Session::get('locale') : $sortBy;
48 48
 
49 49
         if ($trashed) {
50 50
             return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true);
Please login to merge, or discard this patch.
src/Modules/Core/Interfaces/BaseRepositoryInterface.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -2,93 +2,93 @@
 block discarded – undo
2 2
 
3 3
 interface BaseRepositoryInterface
4 4
 {
5
-    /**
6
-     * Fetch all records with relations from the storage.
7
-     *
8
-     * @param  array  $relations
9
-     * @param  array  $sortBy
10
-     * @param  array  $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
14
-    public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
5
+	/**
6
+	 * Fetch all records with relations from the storage.
7
+	 *
8
+	 * @param  array  $relations
9
+	 * @param  array  $sortBy
10
+	 * @param  array  $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14
+	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
15 15
 
16
-    /**
17
-     * Fetch all records with relations from storage in pages.
18
-     *
19
-     * @param  integer $perPage
20
-     * @param  array   $relations
21
-     * @param  array   $sortBy
22
-     * @param  array   $desc
23
-     * @param  array   $columns
24
-     * @return collection
25
-     */
26
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
16
+	/**
17
+	 * Fetch all records with relations from storage in pages.
18
+	 *
19
+	 * @param  integer $perPage
20
+	 * @param  array   $relations
21
+	 * @param  array   $sortBy
22
+	 * @param  array   $desc
23
+	 * @param  array   $columns
24
+	 * @return collection
25
+	 */
26
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
27 27
     
28
-    /**
29
-     * Fetch all records with relations based on
30
-     * the given condition from storage in pages.
31
-     *
32
-     * @param  array   $conditions array of conditions
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
28
+	/**
29
+	 * Fetch all records with relations based on
30
+	 * the given condition from storage in pages.
31
+	 *
32
+	 * @param  array   $conditions array of conditions
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
41 41
 
42
-     /**
43
-      * Save the given model/models to the storage.
44
-      *
45
-      * @param  array   $data
46
-      * @return mixed
47
-      */
48
-    public function save(array $data);
42
+	 /**
43
+	  * Save the given model/models to the storage.
44
+	  *
45
+	  * @param  array   $data
46
+	  * @return mixed
47
+	  */
48
+	public function save(array $data);
49 49
 
50
-    /**
51
-     * Delete record from the storage based on the given
52
-     * condition.
53
-     *
54
-     * @param  var     $value condition value
55
-     * @param  string  $attribute condition column name
56
-     * @return integer affected rows
57
-     */
58
-    public function delete($value, $attribute = 'id');
50
+	/**
51
+	 * Delete record from the storage based on the given
52
+	 * condition.
53
+	 *
54
+	 * @param  var     $value condition value
55
+	 * @param  string  $attribute condition column name
56
+	 * @return integer affected rows
57
+	 */
58
+	public function delete($value, $attribute = 'id');
59 59
     
60
-    /**
61
-     * Fetch records from the storage based on the given
62
-     * id.
63
-     *
64
-     * @param  integer $id
65
-     * @param  array   $relations
66
-     * @param  array   $columns
67
-     * @return object
68
-     */
69
-    public function find($id, $relations = [], $columns = ['*']);
60
+	/**
61
+	 * Fetch records from the storage based on the given
62
+	 * id.
63
+	 *
64
+	 * @param  integer $id
65
+	 * @param  array   $relations
66
+	 * @param  array   $columns
67
+	 * @return object
68
+	 */
69
+	public function find($id, $relations = [], $columns = ['*']);
70 70
     
71
-    /**
72
-     * Fetch records from the storage based on the given
73
-     * condition.
74
-     *
75
-     * @param  array   $conditions array of conditions
76
-     * @param  array   $relations
77
-     * @param  array   $sortBy
78
-     * @param  array   $desc
79
-     * @param  array   $columns
80
-     * @return collection
81
-     */
82
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
71
+	/**
72
+	 * Fetch records from the storage based on the given
73
+	 * condition.
74
+	 *
75
+	 * @param  array   $conditions array of conditions
76
+	 * @param  array   $relations
77
+	 * @param  array   $sortBy
78
+	 * @param  array   $desc
79
+	 * @param  array   $columns
80
+	 * @return collection
81
+	 */
82
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
83 83
 
84
-    /**
85
-     * Fetch the first record fro the storage based on the given
86
-     * condition.
87
-     *
88
-     * @param  array   $conditions array of conditions
89
-     * @param  array   $relations
90
-     * @param  array   $columns
91
-     * @return object
92
-     */
93
-    public function first($conditions, $relations = [], $columns = ['*']);
84
+	/**
85
+	 * Fetch the first record fro the storage based on the given
86
+	 * condition.
87
+	 *
88
+	 * @param  array   $conditions array of conditions
89
+	 * @param  array   $relations
90
+	 * @param  array   $columns
91
+	 * @return object
92
+	 */
93
+	public function first($conditions, $relations = [], $columns = ['*']);
94 94
 }
Please login to merge, or discard this patch.
src/Modules/Core/Interfaces/BaseServiceInterface.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -2,93 +2,93 @@
 block discarded – undo
2 2
 
3 3
 interface BaseServiceInterface
4 4
 {
5
-    /**
6
-     * Fetch all records with relations from the storage.
7
-     *
8
-     * @param  array  $relations
9
-     * @param  array  $sortBy
10
-     * @param  array  $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
14
-    public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
5
+	/**
6
+	 * Fetch all records with relations from the storage.
7
+	 *
8
+	 * @param  array  $relations
9
+	 * @param  array  $sortBy
10
+	 * @param  array  $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14
+	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
15 15
 
16
-    /**
17
-     * Fetch all records with relations from storage in pages.
18
-     *
19
-     * @param  integer $perPage
20
-     * @param  array   $relations
21
-     * @param  array   $sortBy
22
-     * @param  array   $desc
23
-     * @param  array   $columns
24
-     * @return collection
25
-     */
26
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
16
+	/**
17
+	 * Fetch all records with relations from storage in pages.
18
+	 *
19
+	 * @param  integer $perPage
20
+	 * @param  array   $relations
21
+	 * @param  array   $sortBy
22
+	 * @param  array   $desc
23
+	 * @param  array   $columns
24
+	 * @return collection
25
+	 */
26
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
27 27
     
28
-    /**
29
-     * Fetch all records with relations based on
30
-     * the given condition from storage in pages.
31
-     *
32
-     * @param  array   $conditions array of conditions
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
28
+	/**
29
+	 * Fetch all records with relations based on
30
+	 * the given condition from storage in pages.
31
+	 *
32
+	 * @param  array   $conditions array of conditions
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
41 41
 
42
-     /**
43
-      * Save the given model/models to the storage.
44
-      *
45
-      * @param  array   $data
46
-      * @return mixed
47
-      */
48
-    public function save(array $data);
42
+	 /**
43
+	  * Save the given model/models to the storage.
44
+	  *
45
+	  * @param  array   $data
46
+	  * @return mixed
47
+	  */
48
+	public function save(array $data);
49 49
 
50
-    /**
51
-     * Delete record from the storage based on the given
52
-     * condition.
53
-     *
54
-     * @param  var     $value condition value
55
-     * @param  string  $attribute condition column name
56
-     * @return integer affected rows
57
-     */
58
-    public function delete($value, $attribute = 'id');
50
+	/**
51
+	 * Delete record from the storage based on the given
52
+	 * condition.
53
+	 *
54
+	 * @param  var     $value condition value
55
+	 * @param  string  $attribute condition column name
56
+	 * @return integer affected rows
57
+	 */
58
+	public function delete($value, $attribute = 'id');
59 59
     
60
-    /**
61
-     * Fetch records from the storage based on the given
62
-     * id.
63
-     *
64
-     * @param  integer $id
65
-     * @param  array   $relations
66
-     * @param  array   $columns
67
-     * @return object
68
-     */
69
-    public function find($id, $relations = [], $columns = ['*']);
60
+	/**
61
+	 * Fetch records from the storage based on the given
62
+	 * id.
63
+	 *
64
+	 * @param  integer $id
65
+	 * @param  array   $relations
66
+	 * @param  array   $columns
67
+	 * @return object
68
+	 */
69
+	public function find($id, $relations = [], $columns = ['*']);
70 70
     
71
-    /**
72
-     * Fetch records from the storage based on the given
73
-     * condition.
74
-     *
75
-     * @param  array   $conditions array of conditions
76
-     * @param  array   $relations
77
-     * @param  array   $sortBy
78
-     * @param  array   $desc
79
-     * @param  array   $columns
80
-     * @return collection
81
-     */
82
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
71
+	/**
72
+	 * Fetch records from the storage based on the given
73
+	 * condition.
74
+	 *
75
+	 * @param  array   $conditions array of conditions
76
+	 * @param  array   $relations
77
+	 * @param  array   $sortBy
78
+	 * @param  array   $desc
79
+	 * @param  array   $columns
80
+	 * @return collection
81
+	 */
82
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = ['*']);
83 83
 
84
-    /**
85
-     * Fetch the first record fro the storage based on the given
86
-     * condition.
87
-     *
88
-     * @param  array   $conditions array of conditions
89
-     * @param  array   $relations
90
-     * @param  array   $columns
91
-     * @return object
92
-     */
93
-    public function first($conditions, $relations = [], $columns = ['*']);
84
+	/**
85
+	 * Fetch the first record fro the storage based on the given
86
+	 * condition.
87
+	 *
88
+	 * @param  array   $conditions array of conditions
89
+	 * @param  array   $relations
90
+	 * @param  array   $columns
91
+	 * @return object
92
+	 */
93
+	public function first($conditions, $relations = [], $columns = ['*']);
94 94
 }
Please login to merge, or discard this patch.
src/Modules/Users/Repositories/UserRepository.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 namespace App\Modules\Users\Repositories;
4 4
 
5 5
 use App\Modules\Core\BaseClasses\BaseRepository;
6
-use Illuminate\Support\Arr;
7 6
 use App\Modules\Users\AclUser;
8 7
 
9 8
 class UserRepository extends BaseRepository
Please login to merge, or discard this patch.
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -8,52 +8,52 @@
 block discarded – undo
8 8
 
9 9
 class UserRepository extends BaseRepository
10 10
 {
11
-    /**
12
-     * Init new object.
13
-     *
14
-     * @param   AclUser $model
15
-     * @return  void
16
-     */
17
-    public function __construct(AclUser $model)
18
-    {
19
-        parent::__construct($model);
20
-    }
11
+	/**
12
+	 * Init new object.
13
+	 *
14
+	 * @param   AclUser $model
15
+	 * @return  void
16
+	 */
17
+	public function __construct(AclUser $model)
18
+	{
19
+		parent::__construct($model);
20
+	}
21 21
 
22
-    /**
23
-     * Detach all roles from the given user.
24
-     *
25
-     * @param  mixed $user
26
-     * @return object
27
-     */
28
-    public function detachRoles($user)
29
-    {
30
-        $user = ! is_int($user) ? $user : $this->find($user);
31
-        $user->roles()->detach();
32
-    }
22
+	/**
23
+	 * Detach all roles from the given user.
24
+	 *
25
+	 * @param  mixed $user
26
+	 * @return object
27
+	 */
28
+	public function detachRoles($user)
29
+	{
30
+		$user = ! is_int($user) ? $user : $this->find($user);
31
+		$user->roles()->detach();
32
+	}
33 33
 
34
-    /**
35
-     * Attach role ids to the given user.
36
-     *
37
-     * @param  mixed $user
38
-     * @param  array $roleIds
39
-     * @return object
40
-     */
41
-    public function attachRoles($user, $roleIds)
42
-    {
43
-        $user = ! is_int($user) ? $user : $this->find($user);
44
-        $user->roles()->attach($roleIds);
45
-    }
34
+	/**
35
+	 * Attach role ids to the given user.
36
+	 *
37
+	 * @param  mixed $user
38
+	 * @param  array $roleIds
39
+	 * @return object
40
+	 */
41
+	public function attachRoles($user, $roleIds)
42
+	{
43
+		$user = ! is_int($user) ? $user : $this->find($user);
44
+		$user->roles()->attach($roleIds);
45
+	}
46 46
 
47
-    /**
48
-     * Count the given user the given roles.
49
-     *
50
-     * @param  mixed    $user
51
-     * @param  string[] $roles
52
-     * @return boolean
53
-     */
54
-    public function countRoles($user, $roles)
55
-    {
56
-        $user = ! is_int($user) ? $user : $this->find($user);
57
-        return $user->roles()->whereIn('name', $roles)->count();
58
-    }
47
+	/**
48
+	 * Count the given user the given roles.
49
+	 *
50
+	 * @param  mixed    $user
51
+	 * @param  string[] $roles
52
+	 * @return boolean
53
+	 */
54
+	public function countRoles($user, $roles)
55
+	{
56
+		$user = ! is_int($user) ? $user : $this->find($user);
57
+		return $user->roles()->whereIn('name', $roles)->count();
58
+	}
59 59
 }
Please login to merge, or discard this patch.