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