Completed
Push — master ( cf2713...aee5ae )
by Sherif
02:07
created
src/Modules/Core/Utl/ErrorHandler.php 1 patch
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -2,123 +2,123 @@
 block discarded – undo
2 2
 
3 3
 class ErrorHandler
4 4
 {
5
-    public function unAuthorized()
6
-    {
7
-        $error = ['status' => 401, 'message' => trans('core::errors.unAuthorized')];
8
-        abort($error['status'], $error['message']);
9
-    }
10
-
11
-    public function invalidRefreshToken()
12
-    {
13
-        $error = ['status' => 400, 'message' => trans('core::errors.invalidRefreshToken')];
14
-        abort($error['status'], $error['message']);
15
-    }
16
-
17
-    public function noPermissions()
18
-    {
19
-        $error = ['status' => 403, 'message' => trans('core::errors.noPermissions')];
20
-        abort($error['status'], $error['message']);
21
-    }
22
-
23
-    public function loginFailed()
24
-    {
25
-        $error = ['status' => 400, 'message' => trans('core::errors.loginFailed')];
26
-        abort($error['status'], $error['message']);
27
-    }
28
-
29
-    public function noSocialEmail()
30
-    {
31
-        $error = ['status' => 400, 'message' => trans('core::errors.noSocialEmail')];
32
-        abort($error['status'], $error['message']);
33
-    }
34
-
35
-    public function userAlreadyRegistered()
36
-    {
37
-        $error = ['status' => 400, 'message' => trans('core::errors.userAlreadyRegistered')];
38
-        abort($error['status'], $error['message']);
39
-    }
40
-
41
-    public function connectionError()
42
-    {
43
-        $error = ['status' => 400, 'message' => trans('core::errors.connectionError')];
44
-        abort($error['status'], $error['message']);
45
-    }
46
-
47
-    public function redisNotRunning()
48
-    {
49
-        $error = ['status' => 400, 'message' => trans('core::errors.redisNotRunning')];
50
-        abort($error['status'], $error['message']);
51
-    }
52
-
53
-    public function dbQueryError()
54
-    {
55
-        $error = ['status' => 400, 'message' => trans('core::errors.dbQueryError')];
56
-        abort($error['status'], $error['message']);
57
-    }
58
-
59
-    public function cannotCreateSetting()
60
-    {
61
-        $error = ['status' => 400, 'message' => trans('core::errors.cannotCreateSetting')];
62
-        abort($error['status'], $error['message']);
63
-    }
64
-
65
-    public function cannotUpdateSettingKey()
66
-    {
67
-        $error = ['status' => 400, 'message' => trans('core::errors.cannotUpdateSettingKey')];
68
-        abort($error['status'], $error['message']);
69
-    }
70
-
71
-    public function userIsBlocked()
72
-    {
73
-        $error = ['status' => 403, 'message' => trans('core::errors.userIsBlocked')];
74
-        abort($error['status'], $error['message']);
75
-    }
76
-
77
-    public function emailNotConfirmed()
78
-    {
79
-        $error = ['status' => 403, 'message' => trans('core::errors.emailNotConfirmed')];
80
-        abort($error['status'], $error['message']);
81
-    }
82
-
83
-    public function emailAlreadyConfirmed()
84
-    {
85
-        $error = ['status' => 403, 'message' => trans('core::errors.emailAlreadyConfirmed')];
86
-        abort($error['status'], $error['message']);
87
-    }
88
-
89
-    public function invalidResetToken()
90
-    {
91
-        $error = ['status' => 400, 'message' => trans('core::errors.invalidResetToken')];
92
-        abort($error['status'], $error['message']);
93
-    }
94
-
95
-    public function invalidResetPassword()
96
-    {
97
-        $error = ['status' => 400, 'message' => trans('core::errors.invalidResetPassword')];
98
-        abort($error['status'], $error['message']);
99
-    }
100
-
101
-    public function invalidOldPassword()
102
-    {
103
-        $error = ['status' => 400, 'message' => trans('core::errors.invalidOldPassword')];
104
-        abort($error['status'], $error['message']);
105
-    }
106
-
107
-    public function invalidConfirmationCode()
108
-    {
109
-        $error = ['status' => 400, 'message' => trans('core::errors.invalidConfirmationCode')];
110
-        abort($error['status'], $error['message']);
111
-    }
112
-
113
-    public function notFound($text)
114
-    {
115
-        $error = ['status' => 404, 'message' => trans('core::errors.notFound', ['replace' => $text])];
116
-        abort($error['status'], $error['message']);
117
-    }
118
-
119
-    public function generalError()
120
-    {
121
-        $error = ['status' => 400, 'message' => trans('core::errors.generalError')];
122
-        abort($error['status'], $error['message']);
123
-    }
5
+	public function unAuthorized()
6
+	{
7
+		$error = ['status' => 401, 'message' => trans('core::errors.unAuthorized')];
8
+		abort($error['status'], $error['message']);
9
+	}
10
+
11
+	public function invalidRefreshToken()
12
+	{
13
+		$error = ['status' => 400, 'message' => trans('core::errors.invalidRefreshToken')];
14
+		abort($error['status'], $error['message']);
15
+	}
16
+
17
+	public function noPermissions()
18
+	{
19
+		$error = ['status' => 403, 'message' => trans('core::errors.noPermissions')];
20
+		abort($error['status'], $error['message']);
21
+	}
22
+
23
+	public function loginFailed()
24
+	{
25
+		$error = ['status' => 400, 'message' => trans('core::errors.loginFailed')];
26
+		abort($error['status'], $error['message']);
27
+	}
28
+
29
+	public function noSocialEmail()
30
+	{
31
+		$error = ['status' => 400, 'message' => trans('core::errors.noSocialEmail')];
32
+		abort($error['status'], $error['message']);
33
+	}
34
+
35
+	public function userAlreadyRegistered()
36
+	{
37
+		$error = ['status' => 400, 'message' => trans('core::errors.userAlreadyRegistered')];
38
+		abort($error['status'], $error['message']);
39
+	}
40
+
41
+	public function connectionError()
42
+	{
43
+		$error = ['status' => 400, 'message' => trans('core::errors.connectionError')];
44
+		abort($error['status'], $error['message']);
45
+	}
46
+
47
+	public function redisNotRunning()
48
+	{
49
+		$error = ['status' => 400, 'message' => trans('core::errors.redisNotRunning')];
50
+		abort($error['status'], $error['message']);
51
+	}
52
+
53
+	public function dbQueryError()
54
+	{
55
+		$error = ['status' => 400, 'message' => trans('core::errors.dbQueryError')];
56
+		abort($error['status'], $error['message']);
57
+	}
58
+
59
+	public function cannotCreateSetting()
60
+	{
61
+		$error = ['status' => 400, 'message' => trans('core::errors.cannotCreateSetting')];
62
+		abort($error['status'], $error['message']);
63
+	}
64
+
65
+	public function cannotUpdateSettingKey()
66
+	{
67
+		$error = ['status' => 400, 'message' => trans('core::errors.cannotUpdateSettingKey')];
68
+		abort($error['status'], $error['message']);
69
+	}
70
+
71
+	public function userIsBlocked()
72
+	{
73
+		$error = ['status' => 403, 'message' => trans('core::errors.userIsBlocked')];
74
+		abort($error['status'], $error['message']);
75
+	}
76
+
77
+	public function emailNotConfirmed()
78
+	{
79
+		$error = ['status' => 403, 'message' => trans('core::errors.emailNotConfirmed')];
80
+		abort($error['status'], $error['message']);
81
+	}
82
+
83
+	public function emailAlreadyConfirmed()
84
+	{
85
+		$error = ['status' => 403, 'message' => trans('core::errors.emailAlreadyConfirmed')];
86
+		abort($error['status'], $error['message']);
87
+	}
88
+
89
+	public function invalidResetToken()
90
+	{
91
+		$error = ['status' => 400, 'message' => trans('core::errors.invalidResetToken')];
92
+		abort($error['status'], $error['message']);
93
+	}
94
+
95
+	public function invalidResetPassword()
96
+	{
97
+		$error = ['status' => 400, 'message' => trans('core::errors.invalidResetPassword')];
98
+		abort($error['status'], $error['message']);
99
+	}
100
+
101
+	public function invalidOldPassword()
102
+	{
103
+		$error = ['status' => 400, 'message' => trans('core::errors.invalidOldPassword')];
104
+		abort($error['status'], $error['message']);
105
+	}
106
+
107
+	public function invalidConfirmationCode()
108
+	{
109
+		$error = ['status' => 400, 'message' => trans('core::errors.invalidConfirmationCode')];
110
+		abort($error['status'], $error['message']);
111
+	}
112
+
113
+	public function notFound($text)
114
+	{
115
+		$error = ['status' => 404, 'message' => trans('core::errors.notFound', ['replace' => $text])];
116
+		abort($error['status'], $error['message']);
117
+	}
118
+
119
+	public function generalError()
120
+	{
121
+		$error = ['status' => 400, 'message' => trans('core::errors.generalError')];
122
+		abort($error['status'], $error['message']);
123
+	}
124 124
 }
Please login to merge, or discard this patch.
src/Modules/Core/ModelObservers/SettingsObserver.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -6,67 +6,67 @@
 block discarded – undo
6 6
 class SettingsObserver
7 7
 {
8 8
 
9
-    public function saving($model)
10
-    {
11
-        //
12
-    }
9
+	public function saving($model)
10
+	{
11
+		//
12
+	}
13 13
 
14
-    public function saved($model)
15
-    {
16
-        //
17
-    }
14
+	public function saved($model)
15
+	{
16
+		//
17
+	}
18 18
 
19
-    /**
20
-     * Prevent the creating of the settings.
21
-     *
22
-     * @param  object $model the model beign created.
23
-     * @return void
24
-     */
25
-    public function creating($model)
26
-    {
27
-        \ErrorHandler::cannotCreateSetting();
28
-    }
19
+	/**
20
+	 * Prevent the creating of the settings.
21
+	 *
22
+	 * @param  object $model the model beign created.
23
+	 * @return void
24
+	 */
25
+	public function creating($model)
26
+	{
27
+		\ErrorHandler::cannotCreateSetting();
28
+	}
29 29
 
30
-    public function created($model)
31
-    {
32
-        //
33
-    }
30
+	public function created($model)
31
+	{
32
+		//
33
+	}
34 34
 
35
-    /**
36
-     * Prevent updating of the setting key.
37
-     *
38
-     * @param  object $model the model beign updated.
39
-     * @return void
40
-     */
41
-    public function updating($model)
42
-    {
43
-        if ($model->getOriginal('key') !== $model->key) {
44
-            \ErrorHandler::cannotUpdateSettingKey();
45
-        }
46
-    }
35
+	/**
36
+	 * Prevent updating of the setting key.
37
+	 *
38
+	 * @param  object $model the model beign updated.
39
+	 * @return void
40
+	 */
41
+	public function updating($model)
42
+	{
43
+		if ($model->getOriginal('key') !== $model->key) {
44
+			\ErrorHandler::cannotUpdateSettingKey();
45
+		}
46
+	}
47 47
 
48
-    public function updated($model)
49
-    {
50
-        //
51
-    }
48
+	public function updated($model)
49
+	{
50
+		//
51
+	}
52 52
 
53
-    public function deleting($model)
54
-    {
55
-        //
56
-    }
53
+	public function deleting($model)
54
+	{
55
+		//
56
+	}
57 57
 
58
-    public function deleted($model)
59
-    {
60
-        //
61
-    }
58
+	public function deleted($model)
59
+	{
60
+		//
61
+	}
62 62
 
63
-    public function restoring($model)
64
-    {
65
-        //
66
-    }
63
+	public function restoring($model)
64
+	{
65
+		//
66
+	}
67 67
 
68
-    public function restored($model)
69
-    {
70
-        //
71
-    }
68
+	public function restored($model)
69
+	{
70
+		//
71
+	}
72 72
 }
Please login to merge, or discard this patch.
src/Modules/Core/Traits/Translatable.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -2,46 +2,46 @@
 block discarded – undo
2 2
 
3 3
 trait Translatable
4 4
 {
5
-    /**
6
-     * Create a new model instance that is existing.
7
-     *
8
-     * @param  array  $attributes
9
-     * @param  string|null  $connection
10
-     * @return static
11
-     */
12
-    public function newFromBuilder($attributes = [], $connection = null)
13
-    {
14
-        $model = parent::newFromBuilder($attributes, $connection);
5
+	/**
6
+	 * Create a new model instance that is existing.
7
+	 *
8
+	 * @param  array  $attributes
9
+	 * @param  string|null  $connection
10
+	 * @return static
11
+	 */
12
+	public function newFromBuilder($attributes = [], $connection = null)
13
+	{
14
+		$model = parent::newFromBuilder($attributes, $connection);
15 15
 
16
-        foreach ($model->attributes as $key => $value) {
17
-            if (isset($this->translatable) && in_array($key, $this->translatable)) {
18
-                $model->$key = $this->getTranslatedAttribute($value);
19
-            }
20
-        }
16
+		foreach ($model->attributes as $key => $value) {
17
+			if (isset($this->translatable) && in_array($key, $this->translatable)) {
18
+				$model->$key = $this->getTranslatedAttribute($value);
19
+			}
20
+		}
21 21
 
22
-        return $model;
23
-    }
22
+		return $model;
23
+	}
24 24
 
25
-    /**
26
-     * Returns a translatable model attribute based on the application's locale settings.
27
-     *
28
-     * @param $values
29
-     * @return string
30
-     */
31
-    protected function getTranslatedAttribute($values)
32
-    {
33
-        $values         = json_decode($values);
34
-        $primaryLocale  = \Session::get('locale');
35
-        $fallbackLocale = 'en';
25
+	/**
26
+	 * Returns a translatable model attribute based on the application's locale settings.
27
+	 *
28
+	 * @param $values
29
+	 * @return string
30
+	 */
31
+	protected function getTranslatedAttribute($values)
32
+	{
33
+		$values         = json_decode($values);
34
+		$primaryLocale  = \Session::get('locale');
35
+		$fallbackLocale = 'en';
36 36
 
37
-        if ($primaryLocale == 'all') {
38
-            return $values;
39
-        }
37
+		if ($primaryLocale == 'all') {
38
+			return $values;
39
+		}
40 40
 
41
-        if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) {
42
-            return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : '';
43
-        }
41
+		if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) {
42
+			return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : '';
43
+		}
44 44
 
45
-        return $primaryLocale == 'all' ? $values : $values->$primaryLocale;
46
-    }
45
+		return $primaryLocale == 'all' ? $values : $values->$primaryLocale;
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
             return $values;
39 39
         }
40 40
 
41
-        if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) {
41
+        if ( ! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) {
42 42
             return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : '';
43 43
         }
44 44
 
Please login to merge, or discard this patch.
src/Modules/Notifications/Resources/Lang/en/notifications.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
     
5
-    /**
6
-     * Here goes your notification messages.
7
-     */
5
+	/**
6
+	 * Here goes your notification messages.
7
+	 */
8 8
 
9 9
 ];
Please login to merge, or discard this patch.
files/Handler.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -7,67 +7,67 @@
 block discarded – undo
7 7
 
8 8
 class Handler extends ExceptionHandler
9 9
 {
10
-    /**
11
-     * A list of the exception types that are not reported.
12
-     *
13
-     * @var array
14
-     */
15
-    protected $dontReport = [
16
-        \League\OAuth2\Server\Exception\OAuthServerException::class,
17
-    ];
10
+	/**
11
+	 * A list of the exception types that are not reported.
12
+	 *
13
+	 * @var array
14
+	 */
15
+	protected $dontReport = [
16
+		\League\OAuth2\Server\Exception\OAuthServerException::class,
17
+	];
18 18
 
19
-    /**
20
-     * A list of the inputs that are never flashed for validation exceptions.
21
-     *
22
-     * @var array
23
-     */
24
-    protected $dontFlash = [
25
-        'password',
26
-        'password_confirmation',
27
-    ];
19
+	/**
20
+	 * A list of the inputs that are never flashed for validation exceptions.
21
+	 *
22
+	 * @var array
23
+	 */
24
+	protected $dontFlash = [
25
+		'password',
26
+		'password_confirmation',
27
+	];
28 28
 
29
-    /**
30
-     * Report or log an exception.
31
-     *
32
-     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
33
-     *
34
-     * @param  \Exception  $exception
35
-     * @return void
36
-     */
37
-    public function report(Exception $exception)
38
-    {
39
-        parent::report($exception);
40
-    }
29
+	/**
30
+	 * Report or log an exception.
31
+	 *
32
+	 * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
33
+	 *
34
+	 * @param  \Exception  $exception
35
+	 * @return void
36
+	 */
37
+	public function report(Exception $exception)
38
+	{
39
+		parent::report($exception);
40
+	}
41 41
 
42
-    /**
43
-     * Render an exception into an HTTP response.
44
-     *
45
-     * @param  \Illuminate\Http\Request  $request
46
-     * @param  \Exception  $exception
47
-     * @return \Illuminate\Http\Response
48
-     */
49
-    public function render($request, Exception $exception)
50
-    {
51
-        if ($request->wantsJson()) {
52
-            if ($exception instanceof \Illuminate\Auth\AuthenticationException) {
53
-                \ErrorHandler::unAuthorized();
54
-            }
55
-            if ($exception instanceof \Illuminate\Database\QueryException) {
56
-                \ErrorHandler::dbQueryError();
57
-            } elseif ($exception instanceof \predis\connection\connectionexception) {
58
-                \ErrorHandler::redisNotRunning();
59
-            } elseif ($exception instanceof \GuzzleHttp\Exception\ClientException) {
60
-                \ErrorHandler::connectionError();
61
-            } elseif ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
62
-                $errors = $exception->getStatusCode() === 404 ? 'not found' : $exception->getMessage();
63
-                return \Response::json(['errors' => [$errors]], $exception->getStatusCode());
64
-            } elseif ($exception instanceof \Illuminate\Validation\ValidationException) {
65
-                return \Response::json(['errors' => $exception->errors()], 422);
66
-            } elseif (! $exception instanceof \Symfony\Component\ErrorHandler\Error\FatalError) {
67
-                return parent::render($request, $exception);
68
-            }
69
-        }
42
+	/**
43
+	 * Render an exception into an HTTP response.
44
+	 *
45
+	 * @param  \Illuminate\Http\Request  $request
46
+	 * @param  \Exception  $exception
47
+	 * @return \Illuminate\Http\Response
48
+	 */
49
+	public function render($request, Exception $exception)
50
+	{
51
+		if ($request->wantsJson()) {
52
+			if ($exception instanceof \Illuminate\Auth\AuthenticationException) {
53
+				\ErrorHandler::unAuthorized();
54
+			}
55
+			if ($exception instanceof \Illuminate\Database\QueryException) {
56
+				\ErrorHandler::dbQueryError();
57
+			} elseif ($exception instanceof \predis\connection\connectionexception) {
58
+				\ErrorHandler::redisNotRunning();
59
+			} elseif ($exception instanceof \GuzzleHttp\Exception\ClientException) {
60
+				\ErrorHandler::connectionError();
61
+			} elseif ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
62
+				$errors = $exception->getStatusCode() === 404 ? 'not found' : $exception->getMessage();
63
+				return \Response::json(['errors' => [$errors]], $exception->getStatusCode());
64
+			} elseif ($exception instanceof \Illuminate\Validation\ValidationException) {
65
+				return \Response::json(['errors' => $exception->errors()], 422);
66
+			} elseif (! $exception instanceof \Symfony\Component\ErrorHandler\Error\FatalError) {
67
+				return parent::render($request, $exception);
68
+			}
69
+		}
70 70
         
71
-        return parent::render($request, $exception);
72
-    }
71
+		return parent::render($request, $exception);
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
                 return \Response::json(['errors' => [$errors]], $exception->getStatusCode());
64 64
             } elseif ($exception instanceof \Illuminate\Validation\ValidationException) {
65 65
                 return \Response::json(['errors' => $exception->errors()], 422);
66
-            } elseif (! $exception instanceof \Symfony\Component\ErrorHandler\Error\FatalError) {
66
+            } elseif ( ! $exception instanceof \Symfony\Component\ErrorHandler\Error\FatalError) {
67 67
                 return parent::render($request, $exception);
68 68
             }
69 69
         }
Please login to merge, or discard this patch.
src/Modules/Core/Setting.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -6,37 +6,37 @@
 block discarded – undo
6 6
 class Setting extends Model
7 7
 {
8 8
 
9
-    use SoftDeletes;
10
-    protected $table    = 'settings';
11
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
-    protected $hidden   = ['deleted_at'];
13
-    protected $guarded  = ['id', 'key'];
14
-    protected $fillable = ['name', 'value'];
15
-    public $searchable  = ['name', 'value', 'key'];
9
+	use SoftDeletes;
10
+	protected $table    = 'settings';
11
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
+	protected $hidden   = ['deleted_at'];
13
+	protected $guarded  = ['id', 'key'];
14
+	protected $fillable = ['name', 'value'];
15
+	public $searchable  = ['name', 'value', 'key'];
16 16
     
17
-    public function getCreatedAtAttribute($value)
18
-    {
19
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
20
-    }
17
+	public function getCreatedAtAttribute($value)
18
+	{
19
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
20
+	}
21 21
 
22
-    public function getUpdatedAtAttribute($value)
23
-    {
24
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
25
-    }
22
+	public function getUpdatedAtAttribute($value)
23
+	{
24
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
25
+	}
26 26
 
27
-    public function getDeletedAtAttribute($value)
28
-    {
29
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
30
-    }
27
+	public function getDeletedAtAttribute($value)
28
+	{
29
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
30
+	}
31 31
     
32
-    public function newCollection(array $models = [])
33
-    {
34
-        return parent::newCollection($models)->keyBy('key');
35
-    }
32
+	public function newCollection(array $models = [])
33
+	{
34
+		return parent::newCollection($models)->keyBy('key');
35
+	}
36 36
 
37
-    public static function boot()
38
-    {
39
-        parent::boot();
40
-        Setting::observe(\App::make('App\Modules\Core\ModelObservers\SettingsObserver'));
41
-    }
37
+	public static function boot()
38
+	{
39
+		parent::boot();
40
+		Setting::observe(\App::make('App\Modules\Core\ModelObservers\SettingsObserver'));
41
+	}
42 42
 }
Please login to merge, or discard this patch.
src/Modules/Core/BaseClasses/BaseRepository.php 3 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @param  array   $relations
36 36
      * @param  string  $sortBy
37
-     * @param  boolean $desc
37
+     * @param  integer $desc
38 38
      * @param  array   $columns
39 39
      * @return collection
40 40
      */
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      * @param  integer $perPage
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
      */
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
      * @param  integer $perPage
155 155
      * @param  array   $relations
156 156
      * @param  string  $sortBy
157
-     * @param  boolean $desc
157
+     * @param  integer $desc
158 158
      * @param  array   $columns
159 159
      * @return collection
160 160
      */
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * @param  integer $perPage
173 173
      * @param  array   $relations
174 174
      * @param  string  $sortBy
175
-     * @param  boolean $desc
175
+     * @param  integer $desc
176 176
      * @param  array   $columns
177 177
      * @return collection
178 178
      */
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
      * Save the given model to the storage.
189 189
      *
190 190
      * @param  array $data
191
-     * @return mixed
191
+     * @return boolean
192 192
      */
193 193
     public function save(array $data)
194 194
     {
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
      * @param  array   $conditions array of conditions
478 478
      * @param  array   $relations
479 479
      * @param  string  $sortBy
480
-     * @param  boolean $desc
480
+     * @param  integer $desc
481 481
      * @param  array   $columns
482 482
      * @return collection
483 483
      */
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
      * @param  array   $conditions array of conditions
510 510
      * @param  integer $perPage
511 511
      * @param  string  $sortBy
512
-     * @param  boolean $desc
512
+     * @param  integer $desc
513 513
      * @param  array   $columns
514 514
      * @return collection
515 515
      */
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      */
22 22
     public function __construct($model)
23 23
     {
24
-        $this->model  = $model;
24
+        $this->model = $model;
25 25
     }
26 26
 
27 27
     /**
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
         /**
86 86
          * Construct the select conditions for the model.
87 87
          */
88
-        $model->where(function ($q) use ($query, $conditionColumns, $relations) {
88
+        $model->where(function($q) use ($query, $conditionColumns, $relations) {
89 89
 
90 90
             if (count($conditionColumns)) {
91 91
                 $column = 'LOWER('.array_shift($conditionColumns).')';
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
                     /**
128 128
                      * Construct the relation condition.
129 129
                      */
130
-                    $q->orWhereHas($relation, function ($subModel) use ($query, $relation) {
130
+                    $q->orWhereHas($relation, function($subModel) use ($query, $relation) {
131 131
 
132
-                        $subModel->where(function ($q) use ($query, $relation) {
132
+                        $subModel->where(function($q) use ($query, $relation) {
133 133
 
134 134
                             /**
135 135
                              * Get columns of the relation.
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
         $model      = false;
216 216
         $relations  = [];
217 217
 
218
-        \DB::transaction(function () use (&$model, $relations, $data) {
218
+        \DB::transaction(function() use (&$model, $relations, $data) {
219 219
             
220 220
             $model     = $this->prepareModel($data);
221 221
             $relations = $this->prepareRelations($data, $model);
@@ -236,17 +236,17 @@  discard block
 block discarded – undo
236 236
     public function delete($value, $attribute = 'id')
237 237
     {
238 238
         if ($attribute == 'id') {
239
-            \DB::transaction(function () use ($value) {
239
+            \DB::transaction(function() use ($value) {
240 240
                 $model = $this->model->lockForUpdate()->find($value);
241
-                if (! $model) {
241
+                if ( ! $model) {
242 242
                     \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value);
243 243
                 }
244 244
                 
245 245
                 $model->delete();
246 246
             });
247 247
         } else {
248
-            \DB::transaction(function () use ($value, $attribute) {
249
-                $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) {
248
+            \DB::transaction(function() use ($value, $attribute) {
249
+                $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function($model) {
250 250
                     $model->delete();
251 251
                 });
252 252
             });
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
     {
338 338
         $model = $this->model->onlyTrashed()->find($id);
339 339
 
340
-        if (! $model) {
340
+        if ( ! $model) {
341 341
             \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id);
342 342
         }
343 343
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
          * @var array
362 362
          */
363 363
         $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
364
-        if (! $model) {
364
+        if ( ! $model) {
365 365
             \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']);
366 366
         }
367 367
 
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
                      * If the relation has no value then marke the relation data
412 412
                      * related to the model to be deleted.
413 413
                      */
414
-                    if (! $value || ! count($value)) {
414
+                    if ( ! $value || ! count($value)) {
415 415
                         $relations[$relation] = 'delete';
416 416
                     }
417 417
                 }
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
                             /**
439 439
                              * If model doesn't exists.
440 440
                              */
441
-                            if (! $relationModel) {
441
+                            if ( ! $relationModel) {
442 442
                                 \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
443 443
                             }
444 444
 
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
                                 /**
470 470
                                  * If model doesn't exists.
471 471
                                  */
472
-                                if (! $relationModel) {
472
+                                if ( ! $relationModel) {
473 473
                                     \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
474 474
                                 }
475 475
 
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
         $value      = $removeLast === false ? $value : substr($value, 0, $removeLast);
676 676
         $path       = explode('->', $value);
677 677
         $field      = array_shift($path);
678
-        $result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) {
678
+        $result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function($part) {
679 679
             return '"'.$part.'"';
680 680
         })->implode('.'));
681 681
         
Please login to merge, or discard this patch.
Indentation   +659 added lines, -659 removed lines patch added patch discarded remove patch
@@ -6,676 +6,676 @@
 block discarded – undo
6 6
 
7 7
 abstract class BaseRepository implements BaseRepositoryInterface
8 8
 {
9
-    /**
10
-     * @var object
11
-     */
12
-    public $model;
9
+	/**
10
+	 * @var object
11
+	 */
12
+	public $model;
13 13
     
14
-    /**
15
-     * Init new object.
16
-     *
17
-     * @var mixed model
18
-     * @return  void
19
-     */
20
-    public function __construct($model)
21
-    {
22
-        $this->model  = $model;
23
-    }
24
-
25
-    /**
26
-     * Fetch records with relations based on the given params.
27
-     *
28
-     * @param   string  $relations
29
-     * @param   array   $conditions
30
-     * @param   integer $perPage
31
-     * @param   string  $sortBy
32
-     * @param   boolean $desc
33
-     * @return collection
34
-     */
35
-    public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true)
36
-    {
37
-        unset($conditions['perPage']);
38
-        unset($conditions['sortBy']);
39
-        unset($conditions['sort']);
40
-        unset($conditions['page']);
41
-
42
-        if (count($conditions)) {
43
-            return $this->paginateBy(['and' => $conditions], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
44
-        }
45
-
46
-        return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
47
-    }
48
-
49
-    /**
50
-     * Fetch all records with relations from the storage.
51
-     *
52
-     * @param  array   $relations
53
-     * @param  string  $sortBy
54
-     * @param  boolean $desc
55
-     * @param  array   $columns
56
-     * @return collection
57
-     */
58
-    public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
59
-    {
60
-        $sort = $desc ? 'desc' : 'asc';
61
-        return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns);
62
-    }
63
-
64
-    /**
65
-     * Fetch all records with relations from storage in pages
66
-     * that matche the given query.
67
-     *
68
-     * @param  string  $query
69
-     * @param  integer $perPage
70
-     * @param  array   $relations
71
-     * @param  string  $sortBy
72
-     * @param  boolean $desc
73
-     * @param  array   $columns
74
-     * @return collection
75
-     */
76
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
77
-    {
78
-        $model            = $this->model->with($relations);
79
-        $conditionColumns = $this->model->searchable;
80
-        $sort             = $desc ? 'desc' : 'asc';
81
-
82
-        /**
83
-         * Construct the select conditions for the model.
84
-         */
85
-        $model->where(function ($q) use ($query, $conditionColumns, $relations) {
86
-
87
-            if (count($conditionColumns)) {
88
-                $column = 'LOWER('.array_shift($conditionColumns).')';
89
-                if (Str::contains($column, '->')) {
90
-                    $column = $this->wrapJsonSelector($column);
91
-                }
92
-
93
-                /**
94
-                 * Use the first element in the model columns to construct the first condition.
95
-                 */
96
-                $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%');
97
-            }
98
-
99
-            /**
100
-             * Loop through the rest of the columns to construct or where conditions.
101
-             */
102
-            foreach ($conditionColumns as $column) {
103
-                $column = 'LOWER('.$column.')';
104
-                if (Str::contains($column, '->')) {
105
-                    $column = $this->wrapJsonSelector($column);
106
-                }
107
-
108
-                $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%');
109
-            }
110
-
111
-            /**
112
-             * Loop through the model relations.
113
-             */
114
-            foreach ($relations as $relation) {
115
-                /**
116
-                 * Remove the sub relation if exists.
117
-                 */
118
-                $relation = explode('.', $relation)[0];
119
-
120
-                /**
121
-                 * Try to fetch the relation repository from the core.
122
-                 */
123
-                if (\Core::$relation()) {
124
-                    /**
125
-                     * Construct the relation condition.
126
-                     */
127
-                    $q->orWhereHas($relation, function ($subModel) use ($query, $relation) {
128
-
129
-                        $subModel->where(function ($q) use ($query, $relation) {
130
-
131
-                            /**
132
-                             * Get columns of the relation.
133
-                             */
134
-                            $subConditionColumns = \Core::$relation()->model->searchable;
135
-
136
-                            if (count($subConditionColumns)) {
137
-                                $column = 'LOWER('.array_shift($subConditionColumns).')';
138
-                                if (Str::contains($column, '->')) {
139
-                                    $column = $this->wrapJsonSelector($column);
140
-                                }
141
-
142
-                                /**
143
-                                 * Use the first element in the relation model columns to construct the first condition.
144
-                                 */
145
-                                $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%');
146
-                            }
147
-
148
-                            /**
149
-                             * Loop through the rest of the columns to construct or where conditions.
150
-                             */
151
-                            foreach ($subConditionColumns as $subConditionColumn) {
152
-                                $column = 'LOWER('.$subConditionColumn.')';
153
-                                if (Str::contains($column, '->')) {
154
-                                    $column = $this->wrapJsonSelector($column);
155
-                                }
14
+	/**
15
+	 * Init new object.
16
+	 *
17
+	 * @var mixed model
18
+	 * @return  void
19
+	 */
20
+	public function __construct($model)
21
+	{
22
+		$this->model  = $model;
23
+	}
24
+
25
+	/**
26
+	 * Fetch records with relations based on the given params.
27
+	 *
28
+	 * @param   string  $relations
29
+	 * @param   array   $conditions
30
+	 * @param   integer $perPage
31
+	 * @param   string  $sortBy
32
+	 * @param   boolean $desc
33
+	 * @return collection
34
+	 */
35
+	public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true)
36
+	{
37
+		unset($conditions['perPage']);
38
+		unset($conditions['sortBy']);
39
+		unset($conditions['sort']);
40
+		unset($conditions['page']);
41
+
42
+		if (count($conditions)) {
43
+			return $this->paginateBy(['and' => $conditions], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
44
+		}
45
+
46
+		return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true);
47
+	}
48
+
49
+	/**
50
+	 * Fetch all records with relations from the storage.
51
+	 *
52
+	 * @param  array   $relations
53
+	 * @param  string  $sortBy
54
+	 * @param  boolean $desc
55
+	 * @param  array   $columns
56
+	 * @return collection
57
+	 */
58
+	public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
59
+	{
60
+		$sort = $desc ? 'desc' : 'asc';
61
+		return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns);
62
+	}
63
+
64
+	/**
65
+	 * Fetch all records with relations from storage in pages
66
+	 * that matche the given query.
67
+	 *
68
+	 * @param  string  $query
69
+	 * @param  integer $perPage
70
+	 * @param  array   $relations
71
+	 * @param  string  $sortBy
72
+	 * @param  boolean $desc
73
+	 * @param  array   $columns
74
+	 * @return collection
75
+	 */
76
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
77
+	{
78
+		$model            = $this->model->with($relations);
79
+		$conditionColumns = $this->model->searchable;
80
+		$sort             = $desc ? 'desc' : 'asc';
81
+
82
+		/**
83
+		 * Construct the select conditions for the model.
84
+		 */
85
+		$model->where(function ($q) use ($query, $conditionColumns, $relations) {
86
+
87
+			if (count($conditionColumns)) {
88
+				$column = 'LOWER('.array_shift($conditionColumns).')';
89
+				if (Str::contains($column, '->')) {
90
+					$column = $this->wrapJsonSelector($column);
91
+				}
92
+
93
+				/**
94
+				 * Use the first element in the model columns to construct the first condition.
95
+				 */
96
+				$q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%');
97
+			}
98
+
99
+			/**
100
+			 * Loop through the rest of the columns to construct or where conditions.
101
+			 */
102
+			foreach ($conditionColumns as $column) {
103
+				$column = 'LOWER('.$column.')';
104
+				if (Str::contains($column, '->')) {
105
+					$column = $this->wrapJsonSelector($column);
106
+				}
107
+
108
+				$q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%');
109
+			}
110
+
111
+			/**
112
+			 * Loop through the model relations.
113
+			 */
114
+			foreach ($relations as $relation) {
115
+				/**
116
+				 * Remove the sub relation if exists.
117
+				 */
118
+				$relation = explode('.', $relation)[0];
119
+
120
+				/**
121
+				 * Try to fetch the relation repository from the core.
122
+				 */
123
+				if (\Core::$relation()) {
124
+					/**
125
+					 * Construct the relation condition.
126
+					 */
127
+					$q->orWhereHas($relation, function ($subModel) use ($query, $relation) {
128
+
129
+						$subModel->where(function ($q) use ($query, $relation) {
130
+
131
+							/**
132
+							 * Get columns of the relation.
133
+							 */
134
+							$subConditionColumns = \Core::$relation()->model->searchable;
135
+
136
+							if (count($subConditionColumns)) {
137
+								$column = 'LOWER('.array_shift($subConditionColumns).')';
138
+								if (Str::contains($column, '->')) {
139
+									$column = $this->wrapJsonSelector($column);
140
+								}
141
+
142
+								/**
143
+								 * Use the first element in the relation model columns to construct the first condition.
144
+								 */
145
+								$q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%');
146
+							}
147
+
148
+							/**
149
+							 * Loop through the rest of the columns to construct or where conditions.
150
+							 */
151
+							foreach ($subConditionColumns as $subConditionColumn) {
152
+								$column = 'LOWER('.$subConditionColumn.')';
153
+								if (Str::contains($column, '->')) {
154
+									$column = $this->wrapJsonSelector($column);
155
+								}
156 156
                                 
157
-                                $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%');
158
-                            }
159
-                        });
160
-                    });
161
-                }
162
-            }
163
-        });
157
+								$q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%');
158
+							}
159
+						});
160
+					});
161
+				}
162
+			}
163
+		});
164 164
         
165
-        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
166
-    }
165
+		return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
166
+	}
167 167
     
168
-    /**
169
-     * Fetch all records with relations from storage in pages.
170
-     *
171
-     * @param  integer $perPage
172
-     * @param  array   $relations
173
-     * @param  string  $sortBy
174
-     * @param  boolean $desc
175
-     * @param  array   $columns
176
-     * @return collection
177
-     */
178
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
179
-    {
180
-        $sort = $desc ? 'desc' : 'asc';
181
-        return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns);
182
-    }
183
-
184
-    /**
185
-     * Fetch all records with relations based on
186
-     * the given condition from storage in pages.
187
-     *
188
-     * @param  array   $conditions array of conditions
189
-     * @param  integer $perPage
190
-     * @param  array   $relations
191
-     * @param  string  $sortBy
192
-     * @param  boolean $desc
193
-     * @param  array   $columns
194
-     * @return collection
195
-     */
196
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
197
-    {
198
-        $conditions = $this->constructConditions($conditions, $this->model);
199
-        $sort       = $desc ? 'desc' : 'asc';
200
-        return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
201
-    }
168
+	/**
169
+	 * Fetch all records with relations from storage in pages.
170
+	 *
171
+	 * @param  integer $perPage
172
+	 * @param  array   $relations
173
+	 * @param  string  $sortBy
174
+	 * @param  boolean $desc
175
+	 * @param  array   $columns
176
+	 * @return collection
177
+	 */
178
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
179
+	{
180
+		$sort = $desc ? 'desc' : 'asc';
181
+		return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns);
182
+	}
183
+
184
+	/**
185
+	 * Fetch all records with relations based on
186
+	 * the given condition from storage in pages.
187
+	 *
188
+	 * @param  array   $conditions array of conditions
189
+	 * @param  integer $perPage
190
+	 * @param  array   $relations
191
+	 * @param  string  $sortBy
192
+	 * @param  boolean $desc
193
+	 * @param  array   $columns
194
+	 * @return collection
195
+	 */
196
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
197
+	{
198
+		$conditions = $this->constructConditions($conditions, $this->model);
199
+		$sort       = $desc ? 'desc' : 'asc';
200
+		return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
201
+	}
202 202
     
203
-    /**
204
-     * Save the given model to the storage.
205
-     *
206
-     * @param  array $data
207
-     * @return mixed
208
-     */
209
-    public function save(array $data)
210
-    {
211
-        \Session::put('locale', 'all');
212
-        $model      = false;
213
-        $relations  = [];
214
-
215
-        \DB::transaction(function () use (&$model, $relations, $data) {
203
+	/**
204
+	 * Save the given model to the storage.
205
+	 *
206
+	 * @param  array $data
207
+	 * @return mixed
208
+	 */
209
+	public function save(array $data)
210
+	{
211
+		\Session::put('locale', 'all');
212
+		$model      = false;
213
+		$relations  = [];
214
+
215
+		\DB::transaction(function () use (&$model, $relations, $data) {
216 216
             
217
-            $model     = $this->prepareModel($data);
218
-            $relations = $this->prepareRelations($data, $model);
219
-            $model     = $this->saveModel($model, $relations);
220
-        });
217
+			$model     = $this->prepareModel($data);
218
+			$relations = $this->prepareRelations($data, $model);
219
+			$model     = $this->saveModel($model, $relations);
220
+		});
221 221
             
222
-        return $model;
223
-    }
224
-
225
-    /**
226
-     * Delete record from the storage based on the given
227
-     * condition.
228
-     *
229
-     * @param  var $value condition value
230
-     * @param  string $attribute condition column name
231
-     * @return void
232
-     */
233
-    public function delete($value, $attribute = 'id')
234
-    {
235
-        if ($attribute == 'id') {
236
-            \DB::transaction(function () use ($value) {
237
-                $model = $this->model->lockForUpdate()->find($value);
238
-                if (! $model) {
239
-                    \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value);
240
-                }
222
+		return $model;
223
+	}
224
+
225
+	/**
226
+	 * Delete record from the storage based on the given
227
+	 * condition.
228
+	 *
229
+	 * @param  var $value condition value
230
+	 * @param  string $attribute condition column name
231
+	 * @return void
232
+	 */
233
+	public function delete($value, $attribute = 'id')
234
+	{
235
+		if ($attribute == 'id') {
236
+			\DB::transaction(function () use ($value) {
237
+				$model = $this->model->lockForUpdate()->find($value);
238
+				if (! $model) {
239
+					\ErrorHandler::notFound(class_basename($this->model).' with id : '.$value);
240
+				}
241 241
                 
242
-                $model->delete();
243
-            });
244
-        } else {
245
-            \DB::transaction(function () use ($value, $attribute) {
246
-                $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) {
247
-                    $model->delete();
248
-                });
249
-            });
250
-        }
251
-    }
242
+				$model->delete();
243
+			});
244
+		} else {
245
+			\DB::transaction(function () use ($value, $attribute) {
246
+				$this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) {
247
+					$model->delete();
248
+				});
249
+			});
250
+		}
251
+	}
252 252
     
253
-    /**
254
-     * Fetch records from the storage based on the given
255
-     * id.
256
-     *
257
-     * @param  integer $id
258
-     * @param  string[]   $relations
259
-     * @param  array   $columns
260
-     * @return object
261
-     */
262
-    public function find($id, $relations = [], $columns = ['*'])
263
-    {
264
-        return $this->model->with($relations)->find($id, $columns);
265
-    }
253
+	/**
254
+	 * Fetch records from the storage based on the given
255
+	 * id.
256
+	 *
257
+	 * @param  integer $id
258
+	 * @param  string[]   $relations
259
+	 * @param  array   $columns
260
+	 * @return object
261
+	 */
262
+	public function find($id, $relations = [], $columns = ['*'])
263
+	{
264
+		return $this->model->with($relations)->find($id, $columns);
265
+	}
266 266
     
267
-    /**
268
-     * Fetch records from the storage based on the given
269
-     * condition.
270
-     *
271
-     * @param  array   $conditions array of conditions
272
-     * @param  array   $relations
273
-     * @param  string  $sortBy
274
-     * @param  boolean $desc
275
-     * @param  array   $columns
276
-     * @return collection
277
-     */
278
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
279
-    {
280
-        $conditions = $this->constructConditions($conditions, $this->model);
281
-        $sort       = $desc ? 'desc' : 'asc';
282
-        return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
283
-    }
284
-
285
-    /**
286
-     * Fetch the first record from the storage based on the given
287
-     * condition.
288
-     *
289
-     * @param  array   $conditions array of conditions
290
-     * @param  array   $relations
291
-     * @param  array   $columns
292
-     * @return object
293
-     */
294
-    public function first($conditions, $relations = [], $columns = ['*'])
295
-    {
296
-        $conditions = $this->constructConditions($conditions, $this->model);
297
-        return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);
298
-    }
299
-
300
-    /**
301
-     * Return the deleted models in pages based on the given conditions.
302
-     *
303
-     * @param  array   $conditions array of conditions
304
-     * @param  integer $perPage
305
-     * @param  string  $sortBy
306
-     * @param  boolean $desc
307
-     * @param  array   $columns
308
-     * @return collection
309
-     */
310
-    public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
311
-    {
312
-        unset($conditions['page']);
313
-        unset($conditions['perPage']);
314
-        unset($conditions['sortBy']);
315
-        unset($conditions['sort']);
316
-        $conditions = $this->constructConditions($conditions, $this->model);
317
-        $sort       = $desc ? 'desc' : 'asc';
318
-        $model      = $this->model->onlyTrashed();
319
-
320
-        if (count($conditions['conditionValues'])) {
321
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
322
-        }
323
-
324
-        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
325
-    }
326
-
327
-    /**
328
-     * Restore the deleted model.
329
-     *
330
-     * @param  integer $id
331
-     * @return void
332
-     */
333
-    public function restore($id)
334
-    {
335
-        $model = $this->model->onlyTrashed()->find($id);
336
-
337
-        if (! $model) {
338
-            \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id);
339
-        }
340
-
341
-        $model->restore();
342
-    }
343
-
344
-    /**
345
-     * Fill the model with the given data.
346
-     *
347
-     * @param   array  $data
348
-     *
349
-     * @return  object
350
-     */
351
-    public function prepareModel($data)
352
-    {
353
-        $modelClass = $this->model;
354
-
355
-        /**
356
-         * If the id is present in the data then select the model for updating,
357
-         * else create new model.
358
-         * @var array
359
-         */
360
-        $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
361
-        if (! $model) {
362
-            \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']);
363
-        }
364
-
365
-        /**
366
-         * Construct the model object with the given data,
367
-         * and if there is a relation add it to relations array,
368
-         * then save the model.
369
-         */
370
-        foreach ($data as $key => $value) {
371
-            if (array_search($key, $model->getFillable(), true) !== false) {
372
-                /**
373
-                 * If the attribute isn't a relation and prevent attributes not in the fillable.
374
-                 */
375
-                $model->$key = $value;
376
-            }
377
-        }
378
-
379
-        return $model;
380
-    }
267
+	/**
268
+	 * Fetch records from the storage based on the given
269
+	 * condition.
270
+	 *
271
+	 * @param  array   $conditions array of conditions
272
+	 * @param  array   $relations
273
+	 * @param  string  $sortBy
274
+	 * @param  boolean $desc
275
+	 * @param  array   $columns
276
+	 * @return collection
277
+	 */
278
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
279
+	{
280
+		$conditions = $this->constructConditions($conditions, $this->model);
281
+		$sort       = $desc ? 'desc' : 'asc';
282
+		return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
283
+	}
284
+
285
+	/**
286
+	 * Fetch the first record from the storage based on the given
287
+	 * condition.
288
+	 *
289
+	 * @param  array   $conditions array of conditions
290
+	 * @param  array   $relations
291
+	 * @param  array   $columns
292
+	 * @return object
293
+	 */
294
+	public function first($conditions, $relations = [], $columns = ['*'])
295
+	{
296
+		$conditions = $this->constructConditions($conditions, $this->model);
297
+		return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);
298
+	}
299
+
300
+	/**
301
+	 * Return the deleted models in pages based on the given conditions.
302
+	 *
303
+	 * @param  array   $conditions array of conditions
304
+	 * @param  integer $perPage
305
+	 * @param  string  $sortBy
306
+	 * @param  boolean $desc
307
+	 * @param  array   $columns
308
+	 * @return collection
309
+	 */
310
+	public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
311
+	{
312
+		unset($conditions['page']);
313
+		unset($conditions['perPage']);
314
+		unset($conditions['sortBy']);
315
+		unset($conditions['sort']);
316
+		$conditions = $this->constructConditions($conditions, $this->model);
317
+		$sort       = $desc ? 'desc' : 'asc';
318
+		$model      = $this->model->onlyTrashed();
319
+
320
+		if (count($conditions['conditionValues'])) {
321
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
322
+		}
323
+
324
+		return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
325
+	}
326
+
327
+	/**
328
+	 * Restore the deleted model.
329
+	 *
330
+	 * @param  integer $id
331
+	 * @return void
332
+	 */
333
+	public function restore($id)
334
+	{
335
+		$model = $this->model->onlyTrashed()->find($id);
336
+
337
+		if (! $model) {
338
+			\ErrorHandler::notFound(class_basename($this->model).' with id : '.$id);
339
+		}
340
+
341
+		$model->restore();
342
+	}
343
+
344
+	/**
345
+	 * Fill the model with the given data.
346
+	 *
347
+	 * @param   array  $data
348
+	 *
349
+	 * @return  object
350
+	 */
351
+	public function prepareModel($data)
352
+	{
353
+		$modelClass = $this->model;
354
+
355
+		/**
356
+		 * If the id is present in the data then select the model for updating,
357
+		 * else create new model.
358
+		 * @var array
359
+		 */
360
+		$model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
361
+		if (! $model) {
362
+			\ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']);
363
+		}
364
+
365
+		/**
366
+		 * Construct the model object with the given data,
367
+		 * and if there is a relation add it to relations array,
368
+		 * then save the model.
369
+		 */
370
+		foreach ($data as $key => $value) {
371
+			if (array_search($key, $model->getFillable(), true) !== false) {
372
+				/**
373
+				 * If the attribute isn't a relation and prevent attributes not in the fillable.
374
+				 */
375
+				$model->$key = $value;
376
+			}
377
+		}
378
+
379
+		return $model;
380
+	}
381 381
     
382
-    /**
383
-     * Prepare related models based on the given data for the given model.
384
-     *
385
-     * @param   array  $data
386
-     * @param   object $model
387
-     *
388
-     * @return  array
389
-     */
390
-    public function prepareRelations($data, $model)
391
-    {
392
-        /**
393
-         * Construct the model object with the given data,
394
-         * and if there is a relation add it to relations array,
395
-         * then save the model.
396
-         */
397
-        foreach ($data as $key => $value) {
398
-            /**
399
-             * If the attribute is a relation.
400
-             */
401
-            $relation = \Str::camel($key);
402
-            if (method_exists($model, $relation) && \Core::$relation()) {
403
-                /**
404
-                 * Check if the relation is a collection.
405
-                 */
406
-                if (class_basename($model->$relation) == 'Collection') {
407
-                    /**
408
-                     * If the relation has no value then marke the relation data
409
-                     * related to the model to be deleted.
410
-                     */
411
-                    if (! $value || ! count($value)) {
412
-                        $relations[$relation] = 'delete';
413
-                    }
414
-                }
415
-                if (is_array($value)) {
416
-                    /**
417
-                     * Loop through the relation data.
418
-                     */
419
-                    foreach ($value as $attr => $val) {
420
-                        /**
421
-                         * Get the relation model.
422
-                         */
423
-                        $relationBaseModel = \Core::$relation()->model;
424
-
425
-                        /**
426
-                         * Check if the relation is a collection.
427
-                         */
428
-                        if (class_basename($model->$relation) == 'Collection') {
429
-                            /**
430
-                             * If the id is present in the data then select the relation model for updating,
431
-                             * else create new model.
432
-                             */
433
-                            $relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
434
-
435
-                            /**
436
-                             * If model doesn't exists.
437
-                             */
438
-                            if (! $relationModel) {
439
-                                \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
440
-                            }
441
-
442
-                            /**
443
-                             * Loop through the relation attributes.
444
-                             */
445
-                            foreach ($val as $attr => $val) {
446
-                                /**
447
-                                 * Prevent the sub relations or attributes not in the fillable.
448
-                                 */
449
-                                if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) {
450
-                                    $relationModel->$attr = $val;
451
-                                }
452
-                            }
453
-
454
-                            $relations[$relation][] = $relationModel;
455
-                        } else {
456
-                            /**
457
-                             * Prevent the sub relations.
458
-                             */
459
-                            if (gettype($val) !== 'object' && gettype($val) !== 'array') {
460
-                                /**
461
-                                 * If the id is present in the data then select the relation model for updating,
462
-                                 * else create new model.
463
-                                 */
464
-                                $relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
465
-
466
-                                /**
467
-                                 * If model doesn't exists.
468
-                                 */
469
-                                if (! $relationModel) {
470
-                                    \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
471
-                                }
472
-
473
-                                foreach ($value as $relationAttribute => $relationValue) {
474
-                                    /**
475
-                                     * Prevent attributes not in the fillable.
476
-                                     */
477
-                                    if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) {
478
-                                        $relationModel->$relationAttribute = $relationValue;
479
-                                    }
480
-                                }
481
-
482
-                                $relations[$relation] = $relationModel;
483
-                            }
484
-                        }
485
-                    }
486
-                }
487
-            }
488
-        }
489
-
490
-        return $relations;
491
-    }
492
-
493
-    /**
494
-     * Save the model with related models.
495
-     *
496
-     * @param   object  $model
497
-     * @param   array   $relations
498
-     *
499
-     * @return  object
500
-     */
501
-    public function saveModel($model, $relations)
502
-    {
503
-
504
-        /**
505
-         * Loop through the relations array.
506
-         */
507
-        foreach ($relations as $key => $value) {
508
-            /**
509
-             * If the relation is marked for delete then delete it.
510
-             */
511
-            if ($value == 'delete' && $model->$key()->count()) {
512
-                $model->$key()->delete();
513
-            } elseif (gettype($value) == 'array') {
514
-                /**
515
-                 * Save the model.
516
-                 */
517
-                $model->save();
518
-                $ids = [];
519
-
520
-                /**
521
-                 * Loop through the relations.
522
-                 */
523
-                foreach ($value as $val) {
524
-                    switch (class_basename($model->$key())) {
525
-                        /**
526
-                         * If the relation is one to many then update it's foreign key with
527
-                         * the model id and save it then add its id to ids array to delete all
528
-                         * relations who's id isn't in the ids array.
529
-                         */
530
-                        case 'HasMany':
531
-                            $foreignKeyName       = $model->$key()->getForeignKeyName();
532
-                            $val->$foreignKeyName = $model->id;
533
-                            $val->save();
534
-                            $ids[] = $val->id;
535
-                            break;
536
-
537
-                        /**
538
-                         * If the relation is many to many then add it's id to the ids array to
539
-                         * attache these ids to the model.
540
-                         */
541
-                        case 'BelongsToMany':
542
-                            $val->save();
543
-                            $ids[] = $val->id;
544
-                            break;
545
-                    }
546
-                }
547
-                switch (class_basename($model->$key())) {
548
-                    /**
549
-                     * If the relation is one to many then delete all
550
-                     * relations who's id isn't in the ids array.
551
-                     */
552
-                    case 'HasMany':
553
-                        $model->$key()->whereNotIn('id', $ids)->delete();
554
-                        break;
555
-
556
-                    /**
557
-                     * If the relation is many to many then
558
-                     * detach the previous data and attach
559
-                     * the ids array to the model.
560
-                     */
561
-                    case 'BelongsToMany':
562
-                        $model->$key()->detach();
563
-                        $model->$key()->attach($ids);
564
-                        break;
565
-                }
566
-            } else {
567
-                switch (class_basename($model->$key())) {
568
-                    /**
569
-                     * If the relation is one to one.
570
-                     */
571
-                    case 'HasOne':
572
-                        /**
573
-                         * Save the model.
574
-                         */
575
-                        $model->save();
576
-                        $foreignKeyName         = $model->$key()->getForeignKeyName();
577
-                        $value->$foreignKeyName = $model->id;
578
-                        $value->save();
579
-                        break;
580
-                    case 'BelongsTo':
581
-                        /**
582
-                         * Save the model.
583
-                         */
584
-                        $value->save();
585
-                        $model->$key()->associate($value);
586
-                        break;
587
-                }
588
-            }
589
-        }
590
-
591
-        /**
592
-         * Save the model.
593
-         */
594
-        $model->save();
595
-
596
-        return $model;
597
-    }
598
-
599
-    /**
600
-     * Build the conditions recursively for the retrieving methods.
601
-     * @param  array $conditions
602
-     * @return array
603
-     */
604
-    protected function constructConditions($conditions, $model)
605
-    {
606
-        $conditionString = '';
607
-        $conditionValues = [];
608
-        foreach ($conditions as $key => $value) {
609
-            if (Str::contains($key, '->')) {
610
-                $key = $this->wrapJsonSelector($key);
611
-            }
612
-
613
-            if ($key == 'and') {
614
-                $conditions       = $this->constructConditions($value, $model);
615
-                $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} ';
616
-                $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
617
-            } elseif ($key == 'or') {
618
-                $conditions       = $this->constructConditions($value, $model);
619
-                $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} ';
620
-                $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
621
-            } else {
622
-                if (is_array($value)) {
623
-                    $operator = $value['op'];
624
-                    if (strtolower($operator) == 'between') {
625
-                        $value1 = $value['val1'];
626
-                        $value2 = $value['val2'];
627
-                    } else {
628
-                        $value = Arr::get($value, 'val', '');
629
-                    }
630
-                } else {
631
-                    $operator = '=';
632
-                }
382
+	/**
383
+	 * Prepare related models based on the given data for the given model.
384
+	 *
385
+	 * @param   array  $data
386
+	 * @param   object $model
387
+	 *
388
+	 * @return  array
389
+	 */
390
+	public function prepareRelations($data, $model)
391
+	{
392
+		/**
393
+		 * Construct the model object with the given data,
394
+		 * and if there is a relation add it to relations array,
395
+		 * then save the model.
396
+		 */
397
+		foreach ($data as $key => $value) {
398
+			/**
399
+			 * If the attribute is a relation.
400
+			 */
401
+			$relation = \Str::camel($key);
402
+			if (method_exists($model, $relation) && \Core::$relation()) {
403
+				/**
404
+				 * Check if the relation is a collection.
405
+				 */
406
+				if (class_basename($model->$relation) == 'Collection') {
407
+					/**
408
+					 * If the relation has no value then marke the relation data
409
+					 * related to the model to be deleted.
410
+					 */
411
+					if (! $value || ! count($value)) {
412
+						$relations[$relation] = 'delete';
413
+					}
414
+				}
415
+				if (is_array($value)) {
416
+					/**
417
+					 * Loop through the relation data.
418
+					 */
419
+					foreach ($value as $attr => $val) {
420
+						/**
421
+						 * Get the relation model.
422
+						 */
423
+						$relationBaseModel = \Core::$relation()->model;
424
+
425
+						/**
426
+						 * Check if the relation is a collection.
427
+						 */
428
+						if (class_basename($model->$relation) == 'Collection') {
429
+							/**
430
+							 * If the id is present in the data then select the relation model for updating,
431
+							 * else create new model.
432
+							 */
433
+							$relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
434
+
435
+							/**
436
+							 * If model doesn't exists.
437
+							 */
438
+							if (! $relationModel) {
439
+								\ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']);
440
+							}
441
+
442
+							/**
443
+							 * Loop through the relation attributes.
444
+							 */
445
+							foreach ($val as $attr => $val) {
446
+								/**
447
+								 * Prevent the sub relations or attributes not in the fillable.
448
+								 */
449
+								if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) {
450
+									$relationModel->$attr = $val;
451
+								}
452
+							}
453
+
454
+							$relations[$relation][] = $relationModel;
455
+						} else {
456
+							/**
457
+							 * Prevent the sub relations.
458
+							 */
459
+							if (gettype($val) !== 'object' && gettype($val) !== 'array') {
460
+								/**
461
+								 * If the id is present in the data then select the relation model for updating,
462
+								 * else create new model.
463
+								 */
464
+								$relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
465
+
466
+								/**
467
+								 * If model doesn't exists.
468
+								 */
469
+								if (! $relationModel) {
470
+									\ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']);
471
+								}
472
+
473
+								foreach ($value as $relationAttribute => $relationValue) {
474
+									/**
475
+									 * Prevent attributes not in the fillable.
476
+									 */
477
+									if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) {
478
+										$relationModel->$relationAttribute = $relationValue;
479
+									}
480
+								}
481
+
482
+								$relations[$relation] = $relationModel;
483
+							}
484
+						}
485
+					}
486
+				}
487
+			}
488
+		}
489
+
490
+		return $relations;
491
+	}
492
+
493
+	/**
494
+	 * Save the model with related models.
495
+	 *
496
+	 * @param   object  $model
497
+	 * @param   array   $relations
498
+	 *
499
+	 * @return  object
500
+	 */
501
+	public function saveModel($model, $relations)
502
+	{
503
+
504
+		/**
505
+		 * Loop through the relations array.
506
+		 */
507
+		foreach ($relations as $key => $value) {
508
+			/**
509
+			 * If the relation is marked for delete then delete it.
510
+			 */
511
+			if ($value == 'delete' && $model->$key()->count()) {
512
+				$model->$key()->delete();
513
+			} elseif (gettype($value) == 'array') {
514
+				/**
515
+				 * Save the model.
516
+				 */
517
+				$model->save();
518
+				$ids = [];
519
+
520
+				/**
521
+				 * Loop through the relations.
522
+				 */
523
+				foreach ($value as $val) {
524
+					switch (class_basename($model->$key())) {
525
+						/**
526
+						 * If the relation is one to many then update it's foreign key with
527
+						 * the model id and save it then add its id to ids array to delete all
528
+						 * relations who's id isn't in the ids array.
529
+						 */
530
+						case 'HasMany':
531
+							$foreignKeyName       = $model->$key()->getForeignKeyName();
532
+							$val->$foreignKeyName = $model->id;
533
+							$val->save();
534
+							$ids[] = $val->id;
535
+							break;
536
+
537
+						/**
538
+						 * If the relation is many to many then add it's id to the ids array to
539
+						 * attache these ids to the model.
540
+						 */
541
+						case 'BelongsToMany':
542
+							$val->save();
543
+							$ids[] = $val->id;
544
+							break;
545
+					}
546
+				}
547
+				switch (class_basename($model->$key())) {
548
+					/**
549
+					 * If the relation is one to many then delete all
550
+					 * relations who's id isn't in the ids array.
551
+					 */
552
+					case 'HasMany':
553
+						$model->$key()->whereNotIn('id', $ids)->delete();
554
+						break;
555
+
556
+					/**
557
+					 * If the relation is many to many then
558
+					 * detach the previous data and attach
559
+					 * the ids array to the model.
560
+					 */
561
+					case 'BelongsToMany':
562
+						$model->$key()->detach();
563
+						$model->$key()->attach($ids);
564
+						break;
565
+				}
566
+			} else {
567
+				switch (class_basename($model->$key())) {
568
+					/**
569
+					 * If the relation is one to one.
570
+					 */
571
+					case 'HasOne':
572
+						/**
573
+						 * Save the model.
574
+						 */
575
+						$model->save();
576
+						$foreignKeyName         = $model->$key()->getForeignKeyName();
577
+						$value->$foreignKeyName = $model->id;
578
+						$value->save();
579
+						break;
580
+					case 'BelongsTo':
581
+						/**
582
+						 * Save the model.
583
+						 */
584
+						$value->save();
585
+						$model->$key()->associate($value);
586
+						break;
587
+				}
588
+			}
589
+		}
590
+
591
+		/**
592
+		 * Save the model.
593
+		 */
594
+		$model->save();
595
+
596
+		return $model;
597
+	}
598
+
599
+	/**
600
+	 * Build the conditions recursively for the retrieving methods.
601
+	 * @param  array $conditions
602
+	 * @return array
603
+	 */
604
+	protected function constructConditions($conditions, $model)
605
+	{
606
+		$conditionString = '';
607
+		$conditionValues = [];
608
+		foreach ($conditions as $key => $value) {
609
+			if (Str::contains($key, '->')) {
610
+				$key = $this->wrapJsonSelector($key);
611
+			}
612
+
613
+			if ($key == 'and') {
614
+				$conditions       = $this->constructConditions($value, $model);
615
+				$conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} ';
616
+				$conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
617
+			} elseif ($key == 'or') {
618
+				$conditions       = $this->constructConditions($value, $model);
619
+				$conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} ';
620
+				$conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
621
+			} else {
622
+				if (is_array($value)) {
623
+					$operator = $value['op'];
624
+					if (strtolower($operator) == 'between') {
625
+						$value1 = $value['val1'];
626
+						$value2 = $value['val2'];
627
+					} else {
628
+						$value = Arr::get($value, 'val', '');
629
+					}
630
+				} else {
631
+					$operator = '=';
632
+				}
633 633
                 
634
-                if (strtolower($operator) == 'between') {
635
-                    $conditionString  .= $key.' >= ? and ';
636
-                    $conditionValues[] = $value1;
637
-
638
-                    $conditionString  .= $key.' <= ? {op} ';
639
-                    $conditionValues[] = $value2;
640
-                } elseif (strtolower($operator) == 'in') {
641
-                    $conditionValues  = array_merge($conditionValues, $value);
642
-                    $inBindingsString = rtrim(str_repeat('?,', count($value)), ',');
643
-                    $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} ';
644
-                } elseif (strtolower($operator) == 'null') {
645
-                    $conditionString .= $key.' is null {op} ';
646
-                } elseif (strtolower($operator) == 'not null') {
647
-                    $conditionString .= $key.' is not null {op} ';
648
-                } elseif (strtolower($operator) == 'has') {
649
-                    $sql              = $model->withTrashed()->has($key)->toSql();
650
-                    $conditions       = $this->constructConditions($value, $model->$key()->getRelated());
651
-                    $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} ';
652
-                    $conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
653
-                } else {
654
-                    $conditionString  .= $key.' '.$operator.' ? {op} ';
655
-                    $conditionValues[] = $value;
656
-                }
657
-            }
658
-        }
659
-        $conditionString = '('.rtrim($conditionString, '{op} ').')';
660
-        return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
661
-    }
662
-
663
-    /**
664
-     * Wrap the given JSON selector.
665
-     *
666
-     * @param  string  $value
667
-     * @return string
668
-     */
669
-    protected function wrapJsonSelector($value)
670
-    {
671
-        $removeLast = strpos($value, ')');
672
-        $value      = $removeLast === false ? $value : substr($value, 0, $removeLast);
673
-        $path       = explode('->', $value);
674
-        $field      = array_shift($path);
675
-        $result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) {
676
-            return '"'.$part.'"';
677
-        })->implode('.'));
634
+				if (strtolower($operator) == 'between') {
635
+					$conditionString  .= $key.' >= ? and ';
636
+					$conditionValues[] = $value1;
637
+
638
+					$conditionString  .= $key.' <= ? {op} ';
639
+					$conditionValues[] = $value2;
640
+				} elseif (strtolower($operator) == 'in') {
641
+					$conditionValues  = array_merge($conditionValues, $value);
642
+					$inBindingsString = rtrim(str_repeat('?,', count($value)), ',');
643
+					$conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} ';
644
+				} elseif (strtolower($operator) == 'null') {
645
+					$conditionString .= $key.' is null {op} ';
646
+				} elseif (strtolower($operator) == 'not null') {
647
+					$conditionString .= $key.' is not null {op} ';
648
+				} elseif (strtolower($operator) == 'has') {
649
+					$sql              = $model->withTrashed()->has($key)->toSql();
650
+					$conditions       = $this->constructConditions($value, $model->$key()->getRelated());
651
+					$conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} ';
652
+					$conditionValues  = array_merge($conditionValues, $conditions['conditionValues']);
653
+				} else {
654
+					$conditionString  .= $key.' '.$operator.' ? {op} ';
655
+					$conditionValues[] = $value;
656
+				}
657
+			}
658
+		}
659
+		$conditionString = '('.rtrim($conditionString, '{op} ').')';
660
+		return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
661
+	}
662
+
663
+	/**
664
+	 * Wrap the given JSON selector.
665
+	 *
666
+	 * @param  string  $value
667
+	 * @return string
668
+	 */
669
+	protected function wrapJsonSelector($value)
670
+	{
671
+		$removeLast = strpos($value, ')');
672
+		$value      = $removeLast === false ? $value : substr($value, 0, $removeLast);
673
+		$path       = explode('->', $value);
674
+		$field      = array_shift($path);
675
+		$result     = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) {
676
+			return '"'.$part.'"';
677
+		})->implode('.'));
678 678
         
679
-        return $removeLast === false ? $result : $result.')';
680
-    }
679
+		return $removeLast === false ? $result : $result.')';
680
+	}
681 681
 }
Please login to merge, or discard this patch.
src/Modules/Notifications/Notifications/ConfirmEmail.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -9,41 +9,41 @@
 block discarded – undo
9 9
 
10 10
 class ConfirmEmail extends Notification implements ShouldQueue
11 11
 {
12
-    use Queueable;
12
+	use Queueable;
13 13
 
14
-    /**
15
-     * Init new object.
16
-     *
17
-     * @return  void
18
-     */
19
-    public function __construct()
20
-    {
21
-        //
22
-    }
14
+	/**
15
+	 * Init new object.
16
+	 *
17
+	 * @return  void
18
+	 */
19
+	public function __construct()
20
+	{
21
+		//
22
+	}
23 23
 
24
-    /**
25
-     * Get the notification's delivery channels.
26
-     *
27
-     * @param  mixed  $notifiable
28
-     * @return string[]
29
-     */
30
-    public function via($notifiable)
31
-    {
32
-        return ['mail'];
33
-    }
24
+	/**
25
+	 * Get the notification's delivery channels.
26
+	 *
27
+	 * @param  mixed  $notifiable
28
+	 * @return string[]
29
+	 */
30
+	public function via($notifiable)
31
+	{
32
+		return ['mail'];
33
+	}
34 34
 
35
-    /**
36
-     * Get the mail representation of the notification.
37
-     *
38
-     * @param  mixed  $notifiable
39
-     * @return \Illuminate\Notifications\Messages\MailMessage
40
-     */
41
-    public function toMail($notifiable)
42
-    {
43
-        return (new MailMessage)
44
-            ->subject('Email verification')
45
-            ->line('Email verification')
46
-            ->line('To validate your email click on the button below')
47
-            ->action('Verify your email', config('skeleton.confrim_email_url').'/'.$notifiable->confirmation_code);
48
-    }
35
+	/**
36
+	 * Get the mail representation of the notification.
37
+	 *
38
+	 * @param  mixed  $notifiable
39
+	 * @return \Illuminate\Notifications\Messages\MailMessage
40
+	 */
41
+	public function toMail($notifiable)
42
+	{
43
+		return (new MailMessage)
44
+			->subject('Email verification')
45
+			->line('Email verification')
46
+			->line('To validate your email click on the button below')
47
+			->action('Verify your email', config('skeleton.confrim_email_url').'/'.$notifiable->confirmation_code);
48
+	}
49 49
 }
Please login to merge, or discard this patch.
src/Modules/Notifications/Notifications/ResetPassword.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -9,43 +9,43 @@
 block discarded – undo
9 9
 
10 10
 class ResetPassword extends Notification implements ShouldQueue
11 11
 {
12
-    use Queueable;
12
+	use Queueable;
13 13
 
14
-    protected $token;
14
+	protected $token;
15 15
 
16
-    /**
17
-     * Init new object.
18
-     *
19
-     * @return  void
20
-     */
21
-    public function __construct($token)
22
-    {
23
-        $this->token = $token;
24
-    }
16
+	/**
17
+	 * Init new object.
18
+	 *
19
+	 * @return  void
20
+	 */
21
+	public function __construct($token)
22
+	{
23
+		$this->token = $token;
24
+	}
25 25
 
26
-    /**
27
-     * Get the notification's delivery channels.
28
-     *
29
-     * @param  mixed  $notifiable
30
-     * @return string[]
31
-     */
32
-    public function via($notifiable)
33
-    {
34
-        return ['mail'];
35
-    }
26
+	/**
27
+	 * Get the notification's delivery channels.
28
+	 *
29
+	 * @param  mixed  $notifiable
30
+	 * @return string[]
31
+	 */
32
+	public function via($notifiable)
33
+	{
34
+		return ['mail'];
35
+	}
36 36
 
37
-    /**
38
-     * Get the mail representation of the notification.
39
-     *
40
-     * @param  mixed  $notifiable
41
-     * @return \Illuminate\Notifications\Messages\MailMessage
42
-     */
43
-    public function toMail($notifiable)
44
-    {
45
-        return (new MailMessage)
46
-            ->subject('Reset passowrd')
47
-            ->line('Reset passowrd')
48
-            ->line('To reset your password click on the button below')
49
-            ->action('Reset password', config('skeleton.reset_password_url').'/'.$this->token);
50
-    }
37
+	/**
38
+	 * Get the mail representation of the notification.
39
+	 *
40
+	 * @param  mixed  $notifiable
41
+	 * @return \Illuminate\Notifications\Messages\MailMessage
42
+	 */
43
+	public function toMail($notifiable)
44
+	{
45
+		return (new MailMessage)
46
+			->subject('Reset passowrd')
47
+			->line('Reset passowrd')
48
+			->line('To reset your password click on the button below')
49
+			->action('Reset password', config('skeleton.reset_password_url').'/'.$this->token);
50
+	}
51 51
 }
Please login to merge, or discard this patch.