Completed
Push — master ( 262a61...e9fbf8 )
by Sherif
02:59
created
src/Modules/V1/Acl/Http/Controllers/UsersController.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -7,168 +7,168 @@
 block discarded – undo
7 7
 
8 8
 class UsersController extends BaseApiController
9 9
 {
10
-    /**
11
-     * The name of the model that is used by the base api controller 
12
-     * to preform actions like (add, edit ... etc).
13
-     * @var string
14
-     */
15
-    protected $model               = 'users';
16
-
17
-    /**
18
-     * List of all route actions that the base api controller
19
-     * will skip permissions check for them.
20
-     * @var array
21
-     */
22
-    protected $skipPermissionCheck = ['account', 'logout', 'block', 'unblock', 'editprofile', 'sendreset'];
23
-
24
-    /**
25
-     * List of all route actions that the base api controller
26
-     * will skip login check for them.
27
-     * @var array
28
-     */
29
-    protected $skipLoginCheck      = ['login', 'register', 'sendreset', 'resetpassword'];
30
-
31
-    /**
32
-     * The validations rules used by the base api controller
33
-     * to check before add.
34
-     * @var array
35
-     */
36
-    protected $validationRules     = [
37
-    'email'    => 'required|email|unique:users,email,{id}',
38
-    'password' => 'min:6'
39
-    ];
40
-
41
-    /**
42
-     * Return the logged in user account.
43
-     * 
44
-     * @return object
45
-     */
46
-    public function getAccount()
47
-    {
48
-       $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
49
-       return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200);
50
-    }
51
-
52
-    /**
53
-     * Block the user.
54
-     *
55
-     * @param  integer  $user_id
56
-     * @return void
57
-     */
58
-    public function getBlock($user_id)
59
-    {
60
-        return \Response::json(\Core::users()->block($user_id), 200);
61
-    }
62
-
63
-    /**
64
-     * Unblock the user.
65
-     *
66
-     * @param  integer  $user_id
67
-     * @return void
68
-     */
69
-    public function getUnblock($user_id)
70
-    {
71
-        return \Response::json(\Core::users()->unblock($user_id), 200);
72
-    }
73
-
74
-    /**
75
-     * Logout the user.
76
-     * 
77
-     * @return void
78
-     */
79
-    public function getLogout()
80
-    {
81
-        return \Response::json(\Core::users()->logout(), 200);
82
-    }
83
-
84
-    /**
85
-     * Handle a registration request.
86
-     *
87
-     * @param  \Illuminate\Http\Request  $request
88
-     * @return \Illuminate\Http\Response
89
-     */
90
-    public function postRegister(Request $request)
91
-    {
92
-        $this->validate($request, [
93
-            'email'    => 'email|unique:users,email,{id}', 
94
-            'password' => 'min:6'
95
-            ]);
96
-
97
-        return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
98
-    }
99
-
100
-    /**
101
-     * Handle a login request of the none admin to the application.
102
-     *
103
-     * @param  \Illuminate\Http\Request  $request
104
-     * @return \Illuminate\Http\Response
105
-     */
106
-    public function postLogin(Request $request)
107
-    {
108
-        $this->validate($request, [
109
-            'email'    => 'required|email', 
110
-            'password' => 'required|min:6',
111
-            'admin'    => 'boolean'
112
-            ]);
113
-
114
-        return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
115
-    }
116
-
117
-    /**
118
-     * Handle an assign groups to user request.
119
-     *
120
-     * @param  \Illuminate\Http\Request  $request
121
-     * @return \Illuminate\Http\Response
122
-     */
123
-    public function postAssigngroups(Request $request)
124
-    {
125
-        $this->validate($request, [
126
-            'group_ids' => 'required|exists:groups,id', 
127
-            'user_id'   => 'required|exists:users,id'
128
-            ]);
129
-
130
-        return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
131
-    }
132
-
133
-    /**
134
-     * Handle the editing of the user profile.
135
-     *
136
-     * @param  \Illuminate\Http\Request  $request
137
-     * @return \Illuminate\Http\Response
138
-     */
139
-    public function postEditprofile(Request $request)
140
-    {
141
-        return \Response::json(\Core::users()->editProfile($request->all()), 200);
142
-    }
143
-
144
-    /**
145
-     * Send a reset link to the given user.
146
-     *
147
-     * @param  \Illuminate\Http\Request  $request
148
-     * @return \Illuminate\Http\Response
149
-     */
150
-    public function postSendreset(Request $request)
151
-    {
152
-        $this->validate($request, ['email' => 'required|email', 'url' => 'required|url']);
153
-
154
-        return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200);
155
-    }
156
-
157
-    /**
158
-     * Reset the given user's password.
159
-     *
160
-     * @param  \Illuminate\Http\Request  $request
161
-     * @return \Illuminate\Http\Response
162
-     */
163
-    public function postResetpassword(Request $request)
164
-    {
165
-        $this->validate($request, [
166
-            'token'                 => 'required',
167
-            'email'                 => 'required|email',
168
-            'password'              => 'required|confirmed|min:6',
169
-            'password_confirmation' => 'required',
170
-        ]);
171
-
172
-        return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
173
-    }
10
+	/**
11
+	 * The name of the model that is used by the base api controller 
12
+	 * to preform actions like (add, edit ... etc).
13
+	 * @var string
14
+	 */
15
+	protected $model               = 'users';
16
+
17
+	/**
18
+	 * List of all route actions that the base api controller
19
+	 * will skip permissions check for them.
20
+	 * @var array
21
+	 */
22
+	protected $skipPermissionCheck = ['account', 'logout', 'block', 'unblock', 'editprofile', 'sendreset'];
23
+
24
+	/**
25
+	 * List of all route actions that the base api controller
26
+	 * will skip login check for them.
27
+	 * @var array
28
+	 */
29
+	protected $skipLoginCheck      = ['login', 'register', 'sendreset', 'resetpassword'];
30
+
31
+	/**
32
+	 * The validations rules used by the base api controller
33
+	 * to check before add.
34
+	 * @var array
35
+	 */
36
+	protected $validationRules     = [
37
+	'email'    => 'required|email|unique:users,email,{id}',
38
+	'password' => 'min:6'
39
+	];
40
+
41
+	/**
42
+	 * Return the logged in user account.
43
+	 * 
44
+	 * @return object
45
+	 */
46
+	public function getAccount()
47
+	{
48
+	   $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
49
+	   return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200);
50
+	}
51
+
52
+	/**
53
+	 * Block the user.
54
+	 *
55
+	 * @param  integer  $user_id
56
+	 * @return void
57
+	 */
58
+	public function getBlock($user_id)
59
+	{
60
+		return \Response::json(\Core::users()->block($user_id), 200);
61
+	}
62
+
63
+	/**
64
+	 * Unblock the user.
65
+	 *
66
+	 * @param  integer  $user_id
67
+	 * @return void
68
+	 */
69
+	public function getUnblock($user_id)
70
+	{
71
+		return \Response::json(\Core::users()->unblock($user_id), 200);
72
+	}
73
+
74
+	/**
75
+	 * Logout the user.
76
+	 * 
77
+	 * @return void
78
+	 */
79
+	public function getLogout()
80
+	{
81
+		return \Response::json(\Core::users()->logout(), 200);
82
+	}
83
+
84
+	/**
85
+	 * Handle a registration request.
86
+	 *
87
+	 * @param  \Illuminate\Http\Request  $request
88
+	 * @return \Illuminate\Http\Response
89
+	 */
90
+	public function postRegister(Request $request)
91
+	{
92
+		$this->validate($request, [
93
+			'email'    => 'email|unique:users,email,{id}', 
94
+			'password' => 'min:6'
95
+			]);
96
+
97
+		return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
98
+	}
99
+
100
+	/**
101
+	 * Handle a login request of the none admin to the application.
102
+	 *
103
+	 * @param  \Illuminate\Http\Request  $request
104
+	 * @return \Illuminate\Http\Response
105
+	 */
106
+	public function postLogin(Request $request)
107
+	{
108
+		$this->validate($request, [
109
+			'email'    => 'required|email', 
110
+			'password' => 'required|min:6',
111
+			'admin'    => 'boolean'
112
+			]);
113
+
114
+		return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
115
+	}
116
+
117
+	/**
118
+	 * Handle an assign groups to user request.
119
+	 *
120
+	 * @param  \Illuminate\Http\Request  $request
121
+	 * @return \Illuminate\Http\Response
122
+	 */
123
+	public function postAssigngroups(Request $request)
124
+	{
125
+		$this->validate($request, [
126
+			'group_ids' => 'required|exists:groups,id', 
127
+			'user_id'   => 'required|exists:users,id'
128
+			]);
129
+
130
+		return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
131
+	}
132
+
133
+	/**
134
+	 * Handle the editing of the user profile.
135
+	 *
136
+	 * @param  \Illuminate\Http\Request  $request
137
+	 * @return \Illuminate\Http\Response
138
+	 */
139
+	public function postEditprofile(Request $request)
140
+	{
141
+		return \Response::json(\Core::users()->editProfile($request->all()), 200);
142
+	}
143
+
144
+	/**
145
+	 * Send a reset link to the given user.
146
+	 *
147
+	 * @param  \Illuminate\Http\Request  $request
148
+	 * @return \Illuminate\Http\Response
149
+	 */
150
+	public function postSendreset(Request $request)
151
+	{
152
+		$this->validate($request, ['email' => 'required|email', 'url' => 'required|url']);
153
+
154
+		return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200);
155
+	}
156
+
157
+	/**
158
+	 * Reset the given user's password.
159
+	 *
160
+	 * @param  \Illuminate\Http\Request  $request
161
+	 * @return \Illuminate\Http\Response
162
+	 */
163
+	public function postResetpassword(Request $request)
164
+	{
165
+		$this->validate($request, [
166
+			'token'                 => 'required',
167
+			'email'                 => 'required|email',
168
+			'password'              => 'required|confirmed|min:6',
169
+			'password_confirmation' => 'required',
170
+		]);
171
+
172
+		return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
173
+	}
174 174
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/ModelObservers/AclGroupObserver.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -5,65 +5,65 @@
 block discarded – undo
5 5
  */
6 6
 class AclGroupObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12 12
 
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17 17
 
18
-    public function creating($model)
19
-    {
20
-        //
21
-    }
18
+	public function creating($model)
19
+	{
20
+		//
21
+	}
22 22
 
23
-    public function created($model)
24
-    {
25
-        //
26
-    }
23
+	public function created($model)
24
+	{
25
+		//
26
+	}
27 27
 
28
-    /**
29
-     * Prevent updating of the admin group.
30
-     * 
31
-     * @param  object $model the model beign updated.
32
-     * @return void
33
-     */
34
-    public function updating($model)
35
-    {
36
-        if ($model->getOriginal()['name'] == 'Admin') 
37
-        {
38
-            \ErrorHandler::noPermissions();
39
-        }
40
-    }
28
+	/**
29
+	 * Prevent updating of the admin group.
30
+	 * 
31
+	 * @param  object $model the model beign updated.
32
+	 * @return void
33
+	 */
34
+	public function updating($model)
35
+	{
36
+		if ($model->getOriginal()['name'] == 'Admin') 
37
+		{
38
+			\ErrorHandler::noPermissions();
39
+		}
40
+	}
41 41
 
42
-    public function updated($model)
43
-    {
44
-        //
45
-    }
42
+	public function updated($model)
43
+	{
44
+		//
45
+	}
46 46
 
47
-    /**
48
-     * Soft delete the associated permissions to the deleted group
49
-     * and prevent deleting the admin group.
50
-     * 
51
-     * @param  object $model the delted model.
52
-     * @return void
53
-     */
54
-    public function deleting($model)
55
-    {
56
-        if ($model->getOriginal()['name'] == 'Admin') 
57
-        {
58
-            \ErrorHandler::noPermissions();
59
-        }
47
+	/**
48
+	 * Soft delete the associated permissions to the deleted group
49
+	 * and prevent deleting the admin group.
50
+	 * 
51
+	 * @param  object $model the delted model.
52
+	 * @return void
53
+	 */
54
+	public function deleting($model)
55
+	{
56
+		if ($model->getOriginal()['name'] == 'Admin') 
57
+		{
58
+			\ErrorHandler::noPermissions();
59
+		}
60 60
 
61
-        \DB::table('groups_permissions')->where('group_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()')));
62
-    }
61
+		\DB::table('groups_permissions')->where('group_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()')));
62
+	}
63 63
 
64
-    public function deleted($model)
65
-    {
66
-        //
67
-    }
64
+	public function deleted($model)
65
+	{
66
+		//
67
+	}
68 68
 
69 69
 }
70 70
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Repositories/UserRepository.php 1 patch
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -4,244 +4,244 @@
 block discarded – undo
4 4
 
5 5
 class UserRepository extends AbstractRepository
6 6
 {
7
-    /**
8
-     * Return the model full namespace.
9
-     * 
10
-     * @return string
11
-     */
12
-    protected function getModel()
13
-    {
14
-        return 'App\Modules\V1\Acl\AclUser';
15
-    }
16
-
17
-    /**
18
-     * Check if the logged in user or the given user 
19
-     * has the given permissions on the given model.
20
-     * 
21
-     * @param  string  $nameOfPermission
22
-     * @param  string  $model            
23
-     * @param  boolean $user
24
-     * @return boolean
25
-     */
26
-    public function can($nameOfPermission, $model, $user = false )
27
-    {       
28
-        $user        = $user ?: \JWTAuth::parseToken()->authenticate();
29
-        $permissions = [];
30
-        \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
31
-            $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32
-        });
7
+	/**
8
+	 * Return the model full namespace.
9
+	 * 
10
+	 * @return string
11
+	 */
12
+	protected function getModel()
13
+	{
14
+		return 'App\Modules\V1\Acl\AclUser';
15
+	}
16
+
17
+	/**
18
+	 * Check if the logged in user or the given user 
19
+	 * has the given permissions on the given model.
20
+	 * 
21
+	 * @param  string  $nameOfPermission
22
+	 * @param  string  $model            
23
+	 * @param  boolean $user
24
+	 * @return boolean
25
+	 */
26
+	public function can($nameOfPermission, $model, $user = false )
27
+	{       
28
+		$user        = $user ?: \JWTAuth::parseToken()->authenticate();
29
+		$permissions = [];
30
+		\Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
31
+			$permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32
+		});
33 33
         
34
-        return in_array($nameOfPermission, $permissions);
35
-    }
36
-
37
-    /**
38
-     * Check if the logged in user has the given group.
39
-     * 
40
-     * @param  string  $groupName
41
-     * @return boolean
42
-     */
43
-    public function hasGroup($groupName)
44
-    {
45
-        $groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
46
-        return $groups->lists('name')->search($groupName, true) === false ? false : true;
47
-    }
48
-
49
-    /**
50
-     * Assign the given group ids to the given user.
51
-     * 
52
-     * @param  integer $user_id    
53
-     * @param  array   $group_ids
54
-     * @return object
55
-     */
56
-    public function assignGroups($user_id, $group_ids)
57
-    {
58
-        \DB::transaction(function () use ($user_id, $group_ids) {
59
-            $user = \Core::users()->find($user_id);
60
-            $user->groups()->detach();
61
-            $user->groups()->attach($group_ids);
62
-        });
63
-
64
-        return \Core::users()->find($user_id);
65
-    }
66
-
67
-    /**
68
-     * Handle a login request to the application.
69
-     * 
70
-     * @param  array   $credentials    
71
-     * @param  boolean $adminLogin
72
-     * @return string
73
-     */
74
-    public function login($credentials, $adminLogin = false)
75
-    {
76
-        if ( ! $user = \Core::users()->first(['email' => $credentials['email']])) 
77
-        {
78
-            \ErrorHandler::loginFailed();
79
-        }
80
-        else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
81
-        {
82
-            \ErrorHandler::loginFailed();
83
-        }
84
-        else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
85
-        {
86
-            \ErrorHandler::loginFailed();
87
-        }
88
-        else if ($user->blocked)
89
-        {
90
-            \ErrorHandler::userIsBlocked();
91
-        }
92
-        else if ($token = \JWTAuth::attempt($credentials))
93
-        {
94
-            return $token;
95
-        }
96
-        else
97
-        {
98
-            \ErrorHandler::loginFailed();
99
-        }
100
-    }
101
-
102
-    /**
103
-     * Handle a registration request.
104
-     * 
105
-     * @param  array $credentials
106
-     * @return string
107
-     */
108
-    public function register($credentials)
109
-    {
110
-        return \JWTAuth::fromUser(\Core::users()->model->create($credentials));
111
-    }
112
-
113
-    /**
114
-     * Logout the user.
115
-     * 
116
-     * @return boolean
117
-     */
118
-    public function logout()
119
-    {
120
-        return \JWTAuth::invalidate(\JWTAuth::getToken());
121
-    }
122
-
123
-    /**
124
-     * Block the user.
125
-     *
126
-     * @param  integer $user_id
127
-     * @return object
128
-     */
129
-    public function block($user_id)
130
-    {
131
-        if ( ! $user = \Core::users()->find($user_id)) 
132
-        {
133
-            \ErrorHandler::notFound('user');
134
-        }
135
-        if ( ! $this->hasGroup('Admin'))
136
-        {
137
-            \ErrorHandler::noPermissions();
138
-        }
139
-        else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
140
-        {
141
-            \ErrorHandler::noPermissions();
142
-        }
143
-        else if ($user->groups->lists('name')->search('Admin', true) !== false) 
144
-        {
145
-            \ErrorHandler::noPermissions();
146
-        }
147
-
148
-        $user->blocked = 1;
149
-        $user->save();
34
+		return in_array($nameOfPermission, $permissions);
35
+	}
36
+
37
+	/**
38
+	 * Check if the logged in user has the given group.
39
+	 * 
40
+	 * @param  string  $groupName
41
+	 * @return boolean
42
+	 */
43
+	public function hasGroup($groupName)
44
+	{
45
+		$groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
46
+		return $groups->lists('name')->search($groupName, true) === false ? false : true;
47
+	}
48
+
49
+	/**
50
+	 * Assign the given group ids to the given user.
51
+	 * 
52
+	 * @param  integer $user_id    
53
+	 * @param  array   $group_ids
54
+	 * @return object
55
+	 */
56
+	public function assignGroups($user_id, $group_ids)
57
+	{
58
+		\DB::transaction(function () use ($user_id, $group_ids) {
59
+			$user = \Core::users()->find($user_id);
60
+			$user->groups()->detach();
61
+			$user->groups()->attach($group_ids);
62
+		});
63
+
64
+		return \Core::users()->find($user_id);
65
+	}
66
+
67
+	/**
68
+	 * Handle a login request to the application.
69
+	 * 
70
+	 * @param  array   $credentials    
71
+	 * @param  boolean $adminLogin
72
+	 * @return string
73
+	 */
74
+	public function login($credentials, $adminLogin = false)
75
+	{
76
+		if ( ! $user = \Core::users()->first(['email' => $credentials['email']])) 
77
+		{
78
+			\ErrorHandler::loginFailed();
79
+		}
80
+		else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
81
+		{
82
+			\ErrorHandler::loginFailed();
83
+		}
84
+		else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
85
+		{
86
+			\ErrorHandler::loginFailed();
87
+		}
88
+		else if ($user->blocked)
89
+		{
90
+			\ErrorHandler::userIsBlocked();
91
+		}
92
+		else if ($token = \JWTAuth::attempt($credentials))
93
+		{
94
+			return $token;
95
+		}
96
+		else
97
+		{
98
+			\ErrorHandler::loginFailed();
99
+		}
100
+	}
101
+
102
+	/**
103
+	 * Handle a registration request.
104
+	 * 
105
+	 * @param  array $credentials
106
+	 * @return string
107
+	 */
108
+	public function register($credentials)
109
+	{
110
+		return \JWTAuth::fromUser(\Core::users()->model->create($credentials));
111
+	}
112
+
113
+	/**
114
+	 * Logout the user.
115
+	 * 
116
+	 * @return boolean
117
+	 */
118
+	public function logout()
119
+	{
120
+		return \JWTAuth::invalidate(\JWTAuth::getToken());
121
+	}
122
+
123
+	/**
124
+	 * Block the user.
125
+	 *
126
+	 * @param  integer $user_id
127
+	 * @return object
128
+	 */
129
+	public function block($user_id)
130
+	{
131
+		if ( ! $user = \Core::users()->find($user_id)) 
132
+		{
133
+			\ErrorHandler::notFound('user');
134
+		}
135
+		if ( ! $this->hasGroup('Admin'))
136
+		{
137
+			\ErrorHandler::noPermissions();
138
+		}
139
+		else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
140
+		{
141
+			\ErrorHandler::noPermissions();
142
+		}
143
+		else if ($user->groups->lists('name')->search('Admin', true) !== false) 
144
+		{
145
+			\ErrorHandler::noPermissions();
146
+		}
147
+
148
+		$user->blocked = 1;
149
+		$user->save();
150 150
         
151
-        return $user;
152
-    }
153
-
154
-    /**
155
-     * Unblock the user.
156
-     *
157
-     * @param  integer $user_id
158
-     * @return object
159
-     */
160
-    public function unblock($user_id)
161
-    {
162
-        if ( ! $this->hasGroup('Admin'))
163
-        {
164
-            \ErrorHandler::noPermissions();
165
-        }
166
-
167
-        $user          = \Core::users()->find($user_id);
168
-        $user->blocked = 0;
169
-        $user->save();
170
-
171
-        return $user;
172
-    }
173
-
174
-    /**
175
-     * Handle the editing of the user profile.
176
-     * 
177
-     * @param  array $profile
178
-     * @return object
179
-     */
180
-    public function editProfile($profile)
181
-    {
182
-        unset($profile['email']);
183
-        unset($profile['password']);
184
-        $profile['id'] = \JWTAuth::parseToken()->authenticate()->id;
151
+		return $user;
152
+	}
153
+
154
+	/**
155
+	 * Unblock the user.
156
+	 *
157
+	 * @param  integer $user_id
158
+	 * @return object
159
+	 */
160
+	public function unblock($user_id)
161
+	{
162
+		if ( ! $this->hasGroup('Admin'))
163
+		{
164
+			\ErrorHandler::noPermissions();
165
+		}
166
+
167
+		$user          = \Core::users()->find($user_id);
168
+		$user->blocked = 0;
169
+		$user->save();
170
+
171
+		return $user;
172
+	}
173
+
174
+	/**
175
+	 * Handle the editing of the user profile.
176
+	 * 
177
+	 * @param  array $profile
178
+	 * @return object
179
+	 */
180
+	public function editProfile($profile)
181
+	{
182
+		unset($profile['email']);
183
+		unset($profile['password']);
184
+		$profile['id'] = \JWTAuth::parseToken()->authenticate()->id;
185 185
         
186
-        return $this->save($profile);
187
-    }
188
-
189
-    /**
190
-     * Send a reset link to the given user.
191
-     *
192
-     * @param  string  $url
193
-     * @param  string  $email
194
-     * @return void
195
-     */
196
-    public function sendReset($email, $url)
197
-    {
198
-        view()->composer('auth.emails.password', function($view) use ($url) {
199
-            $view->with(['url' => $url]);
200
-        });
201
-
202
-        $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
203
-            $message->subject('Your Password Reset Link');
204
-        });
205
-
206
-        switch ($response) 
207
-        {
208
-            case \Password::INVALID_USER:
209
-                \ErrorHandler::notFound('email');
210
-        }
211
-    }
212
-
213
-    /**
214
-     * Reset the given user's password.
215
-     *
216
-     * @param  array  $credentials
217
-     * @return integer
218
-     */
219
-    public function resetPassword($credentials)
220
-    {
221
-        $token    = false;
222
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
223
-            $user->password = bcrypt($password);
224
-            $user->save();
225
-
226
-            $token = \JWTAuth::fromUser($user);
227
-        });
228
-
229
-
230
-        switch ($response) {
231
-            case \Password::PASSWORD_RESET:
232
-                return $token;
186
+		return $this->save($profile);
187
+	}
188
+
189
+	/**
190
+	 * Send a reset link to the given user.
191
+	 *
192
+	 * @param  string  $url
193
+	 * @param  string  $email
194
+	 * @return void
195
+	 */
196
+	public function sendReset($email, $url)
197
+	{
198
+		view()->composer('auth.emails.password', function($view) use ($url) {
199
+			$view->with(['url' => $url]);
200
+		});
201
+
202
+		$response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
203
+			$message->subject('Your Password Reset Link');
204
+		});
205
+
206
+		switch ($response) 
207
+		{
208
+			case \Password::INVALID_USER:
209
+				\ErrorHandler::notFound('email');
210
+		}
211
+	}
212
+
213
+	/**
214
+	 * Reset the given user's password.
215
+	 *
216
+	 * @param  array  $credentials
217
+	 * @return integer
218
+	 */
219
+	public function resetPassword($credentials)
220
+	{
221
+		$token    = false;
222
+		$response = \Password::reset($credentials, function ($user, $password) use (&$token) {
223
+			$user->password = bcrypt($password);
224
+			$user->save();
225
+
226
+			$token = \JWTAuth::fromUser($user);
227
+		});
228
+
229
+
230
+		switch ($response) {
231
+			case \Password::PASSWORD_RESET:
232
+				return $token;
233 233
                 
234
-            case \Password::INVALID_TOKEN:
235
-                \ErrorHandler::invalidResetToken('token');
234
+			case \Password::INVALID_TOKEN:
235
+				\ErrorHandler::invalidResetToken('token');
236 236
 
237
-            case \Password::INVALID_PASSWORD:
238
-                \ErrorHandler::invalidResetPassword('email');
237
+			case \Password::INVALID_PASSWORD:
238
+				\ErrorHandler::invalidResetPassword('email');
239 239
 
240
-            case \Password::INVALID_USER:
241
-                \ErrorHandler::notFound('user');
240
+			case \Password::INVALID_USER:
241
+				\ErrorHandler::notFound('user');
242 242
 
243
-            default:
244
-                \ErrorHandler::generalError();
245
-        }
246
-    }
243
+			default:
244
+				\ErrorHandler::generalError();
245
+		}
246
+	}
247 247
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/AbstractRepositories/AbstractRepository.php 1 patch
Indentation   +491 added lines, -491 removed lines patch added patch discarded remove patch
@@ -4,533 +4,533 @@
 block discarded – undo
4 4
 
5 5
 abstract class AbstractRepository implements RepositoryInterface
6 6
 {
7
-    /**
8
-     * The model implementation.
9
-     * 
10
-     * @var model
11
-     */
12
-    public $model;
7
+	/**
8
+	 * The model implementation.
9
+	 * 
10
+	 * @var model
11
+	 */
12
+	public $model;
13 13
     
14
-    /**
15
-     * The config implementation.
16
-     * 
17
-     * @var config
18
-     */
19
-    protected $config;
14
+	/**
15
+	 * The config implementation.
16
+	 * 
17
+	 * @var config
18
+	 */
19
+	protected $config;
20 20
     
21
-    /**
22
-     * Create new AbstractRepository instance.
23
-     */
24
-    public function __construct()
25
-    {   
26
-        $this->config = \CoreConfig::getConfig();
27
-        $this->model  = \App::make($this->getModel());
28
-    }
21
+	/**
22
+	 * Create new AbstractRepository instance.
23
+	 */
24
+	public function __construct()
25
+	{   
26
+		$this->config = \CoreConfig::getConfig();
27
+		$this->model  = \App::make($this->getModel());
28
+	}
29 29
 
30
-    /**
31
-     * Fetch all records with relations from the storage.
32
-     *
33
-     * @param  array   $relations
34
-     * @param  string  $sortBy
35
-     * @param  boolean $desc
36
-     * @param  array   $columns
37
-     * @return collection
38
-     */
39
-    public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
40
-    {
41
-        $sort = $desc ? 'desc' : 'asc';
42
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns);
43
-    }
30
+	/**
31
+	 * Fetch all records with relations from the storage.
32
+	 *
33
+	 * @param  array   $relations
34
+	 * @param  string  $sortBy
35
+	 * @param  boolean $desc
36
+	 * @param  array   $columns
37
+	 * @return collection
38
+	 */
39
+	public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
40
+	{
41
+		$sort = $desc ? 'desc' : 'asc';
42
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns);
43
+	}
44 44
 
45
-    /**
46
-     * Fetch all records with relations from storage in pages 
47
-     * that matche the given query.
48
-     * 
49
-     * @param  string  $query
50
-     * @param  integer $perPage
51
-     * @param  array   $relations
52
-     * @param  string  $sortBy
53
-     * @param  boolean $desc
54
-     * @param  array   $columns
55
-     * @return collection
56
-     */
57
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
58
-    {
59
-        $model            = call_user_func_array("{$this->getModel()}::with", array($relations));
60
-        $conditionColumns = $this->model->getFillable();
61
-        $sort             = $desc ? 'desc' : 'asc';
45
+	/**
46
+	 * Fetch all records with relations from storage in pages 
47
+	 * that matche the given query.
48
+	 * 
49
+	 * @param  string  $query
50
+	 * @param  integer $perPage
51
+	 * @param  array   $relations
52
+	 * @param  string  $sortBy
53
+	 * @param  boolean $desc
54
+	 * @param  array   $columns
55
+	 * @return collection
56
+	 */
57
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
58
+	{
59
+		$model            = call_user_func_array("{$this->getModel()}::with", array($relations));
60
+		$conditionColumns = $this->model->getFillable();
61
+		$sort             = $desc ? 'desc' : 'asc';
62 62
 
63
-        /**
64
-         * Construct the select conditions for the model.
65
-         */
66
-        $model->where(function ($q) use ($query, $conditionColumns, $relations){
63
+		/**
64
+		 * Construct the select conditions for the model.
65
+		 */
66
+		$model->where(function ($q) use ($query, $conditionColumns, $relations){
67 67
 
68
-            /**
69
-             * Use the first element in the model columns to construct the first condition.
70
-             */
71
-            $q->where(\DB::raw('LOWER(CAST(' .array_shift($conditionColumns). ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
68
+			/**
69
+			 * Use the first element in the model columns to construct the first condition.
70
+			 */
71
+			$q->where(\DB::raw('LOWER(CAST(' .array_shift($conditionColumns). ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
72 72
 
73
-            /**
74
-             * Loop through the rest of the columns to construct or where conditions.
75
-             */
76
-            foreach ($conditionColumns as $column) 
77
-            {
78
-                $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
79
-            }
73
+			/**
74
+			 * Loop through the rest of the columns to construct or where conditions.
75
+			 */
76
+			foreach ($conditionColumns as $column) 
77
+			{
78
+				$q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
79
+			}
80 80
 
81
-            /**
82
-             * Loop through the model relations.
83
-             */
84
-            foreach ($relations as $relation) 
85
-            {
86
-                /**
87
-                 * Remove the sub relation if exists.
88
-                 */
89
-                $relation = explode('.', $relation)[0];
81
+			/**
82
+			 * Loop through the model relations.
83
+			 */
84
+			foreach ($relations as $relation) 
85
+			{
86
+				/**
87
+				 * Remove the sub relation if exists.
88
+				 */
89
+				$relation = explode('.', $relation)[0];
90 90
 
91
-                /**
92
-                 * Try to fetch the relation repository from the core.
93
-                 */
94
-                if (\Core::$relation()) 
95
-                {
96
-                    /**
97
-                     * Construct the relation condition.
98
-                     */
99
-                    $q->orWhereHas($relation, function ($subModel) use ($query, $relation){
91
+				/**
92
+				 * Try to fetch the relation repository from the core.
93
+				 */
94
+				if (\Core::$relation()) 
95
+				{
96
+					/**
97
+					 * Construct the relation condition.
98
+					 */
99
+					$q->orWhereHas($relation, function ($subModel) use ($query, $relation){
100 100
 
101
-                        $subModel->where(function ($q) use ($query, $relation){
101
+						$subModel->where(function ($q) use ($query, $relation){
102 102
 
103
-                            /**
104
-                             * Get columns of the relation.
105
-                             */
106
-                            $subConditionColumns = \Core::$relation()->model->getFillable();
103
+							/**
104
+							 * Get columns of the relation.
105
+							 */
106
+							$subConditionColumns = \Core::$relation()->model->getFillable();
107 107
 
108
-                            /**
109
-                             * Use the first element in the relation model columns to construct the first condition.
110
-                             */
111
-                            $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
108
+							/**
109
+							 * Use the first element in the relation model columns to construct the first condition.
110
+							 */
111
+							$q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
112 112
 
113
-                            /**
114
-                             * Loop through the rest of the columns to construct or where conditions.
115
-                             */
116
-                            foreach ($subConditionColumns as $subConditionColumn)
117
-                            {
118
-                                $q->orWhere(\DB::raw('LOWER(CAST(' . $subConditionColumn . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
119
-                            } 
120
-                        });
113
+							/**
114
+							 * Loop through the rest of the columns to construct or where conditions.
115
+							 */
116
+							foreach ($subConditionColumns as $subConditionColumn)
117
+							{
118
+								$q->orWhere(\DB::raw('LOWER(CAST(' . $subConditionColumn . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
119
+							} 
120
+						});
121 121
 
122
-                    });
123
-                }
124
-            }
125
-        });
122
+					});
123
+				}
124
+			}
125
+		});
126 126
         
127
-        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
128
-    }
127
+		return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
128
+	}
129 129
     
130
-    /**
131
-     * Fetch all records with relations from storage in pages.
132
-     * 
133
-     * @param  integer $perPage
134
-     * @param  array   $relations
135
-     * @param  string  $sortBy
136
-     * @param  boolean $desc
137
-     * @param  array   $columns
138
-     * @return collection
139
-     */
140
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
141
-    {
142
-        $sort = $desc ? 'desc' : 'asc';
143
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns);
144
-    }
130
+	/**
131
+	 * Fetch all records with relations from storage in pages.
132
+	 * 
133
+	 * @param  integer $perPage
134
+	 * @param  array   $relations
135
+	 * @param  string  $sortBy
136
+	 * @param  boolean $desc
137
+	 * @param  array   $columns
138
+	 * @return collection
139
+	 */
140
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
141
+	{
142
+		$sort = $desc ? 'desc' : 'asc';
143
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns);
144
+	}
145 145
 
146
-    /**
147
-     * Fetch all records with relations based on
148
-     * the given condition from storage in pages.
149
-     * 
150
-     * @param  array   $conditions array of conditions
151
-     * @param  integer $perPage
152
-     * @param  array   $relations
153
-     * @param  string  $sortBy
154
-     * @param  boolean $desc
155
-     * @param  array   $columns
156
-     * @return collection
157
-     */
158
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
159
-    {
160
-        unset($conditions['page']);
161
-        $conditions = $this->constructConditions($conditions);
162
-        $sort       = $desc ? 'desc' : 'asc';
163
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
164
-    }
146
+	/**
147
+	 * Fetch all records with relations based on
148
+	 * the given condition from storage in pages.
149
+	 * 
150
+	 * @param  array   $conditions array of conditions
151
+	 * @param  integer $perPage
152
+	 * @param  array   $relations
153
+	 * @param  string  $sortBy
154
+	 * @param  boolean $desc
155
+	 * @param  array   $columns
156
+	 * @return collection
157
+	 */
158
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
159
+	{
160
+		unset($conditions['page']);
161
+		$conditions = $this->constructConditions($conditions);
162
+		$sort       = $desc ? 'desc' : 'asc';
163
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
164
+	}
165 165
     
166
-    /**
167
-     * Save the given model to the storage.
168
-     * 
169
-     * @param  array   $data
170
-     * @param  boolean $saveLog
171
-     * @return object
172
-     */
173
-    public function save(array $data, $saveLog = true)
174
-    {
175
-        $model      = false;
176
-        $modelClass = $this->model;
177
-        $relations  = [];
178
-        $with       = [];
166
+	/**
167
+	 * Save the given model to the storage.
168
+	 * 
169
+	 * @param  array   $data
170
+	 * @param  boolean $saveLog
171
+	 * @return object
172
+	 */
173
+	public function save(array $data, $saveLog = true)
174
+	{
175
+		$model      = false;
176
+		$modelClass = $this->model;
177
+		$relations  = [];
178
+		$with       = [];
179 179
 
180
-        \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) {
181
-            /**
182
-             * If the id is present in the data then select the model for updating,
183
-             * else create new model.
184
-             * @var array
185
-             */
186
-            $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
187
-            if ( ! $model) 
188
-            {
189
-                \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
190
-            }
180
+		\DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) {
181
+			/**
182
+			 * If the id is present in the data then select the model for updating,
183
+			 * else create new model.
184
+			 * @var array
185
+			 */
186
+			$model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
187
+			if ( ! $model) 
188
+			{
189
+				\ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
190
+			}
191 191
 
192
-            /**
193
-             * Construct the model object with the given data,
194
-             * and if there is a relation add it to relations array,
195
-             * then save the model.
196
-             */
197
-            foreach ($data as $key => $value) 
198
-            {
199
-                /**
200
-                 * If the attribute is a relation.
201
-                 */
202
-                $relation = camel_case($key);
203
-                if (method_exists($model, $relation))
204
-                {
205
-                    /**
206
-                     * Add the relation to the with array to eager load the created model with the relations.
207
-                     */
208
-                    $with[] = $relation;
192
+			/**
193
+			 * Construct the model object with the given data,
194
+			 * and if there is a relation add it to relations array,
195
+			 * then save the model.
196
+			 */
197
+			foreach ($data as $key => $value) 
198
+			{
199
+				/**
200
+				 * If the attribute is a relation.
201
+				 */
202
+				$relation = camel_case($key);
203
+				if (method_exists($model, $relation))
204
+				{
205
+					/**
206
+					 * Add the relation to the with array to eager load the created model with the relations.
207
+					 */
208
+					$with[] = $relation;
209 209
 
210
-                    /**
211
-                     * Check if the relation is a collection.
212
-                     */
213
-                    if (class_basename($model->$relation) == 'Collection') 
214
-                    {   
215
-                        /**
216
-                         * If the relation has no value then marke the relation data 
217
-                         * related to the model to be deleted.
218
-                         */
219
-                        if ( ! $value || ! count($value)) 
220
-                        {
221
-                            $relations[$relation] = 'delete';
222
-                        }   
223
-                    }
224
-                    if (is_array($value)) 
225
-                    {
226
-                        /**
227
-                         * Loop through the relation data.
228
-                         */
229
-                        foreach ($value as $attr => $val) 
230
-                        {
231
-                            /**
232
-                             * Get the relation model.
233
-                             */
234
-                            $relationBaseModel = \Core::$relation()->model;
210
+					/**
211
+					 * Check if the relation is a collection.
212
+					 */
213
+					if (class_basename($model->$relation) == 'Collection') 
214
+					{   
215
+						/**
216
+						 * If the relation has no value then marke the relation data 
217
+						 * related to the model to be deleted.
218
+						 */
219
+						if ( ! $value || ! count($value)) 
220
+						{
221
+							$relations[$relation] = 'delete';
222
+						}   
223
+					}
224
+					if (is_array($value)) 
225
+					{
226
+						/**
227
+						 * Loop through the relation data.
228
+						 */
229
+						foreach ($value as $attr => $val) 
230
+						{
231
+							/**
232
+							 * Get the relation model.
233
+							 */
234
+							$relationBaseModel = \Core::$relation()->model;
235 235
 
236
-                            /**
237
-                             * Check if the relation is a collection.
238
-                             */
239
-                            if (class_basename($model->$relation) == 'Collection')
240
-                            {
241
-                                /**
242
-                                 * If the id is present in the data then select the relation model for updating,
243
-                                 * else create new model.
244
-                                 */
245
-                                $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
236
+							/**
237
+							 * Check if the relation is a collection.
238
+							 */
239
+							if (class_basename($model->$relation) == 'Collection')
240
+							{
241
+								/**
242
+								 * If the id is present in the data then select the relation model for updating,
243
+								 * else create new model.
244
+								 */
245
+								$relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
246 246
 
247
-                                /**
248
-                                 * If model doesn't exists.
249
-                                 */
250
-                                if ( ! $relationModel) 
251
-                                {
252
-                                    \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
253
-                                }
247
+								/**
248
+								 * If model doesn't exists.
249
+								 */
250
+								if ( ! $relationModel) 
251
+								{
252
+									\ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
253
+								}
254 254
 
255
-                                /**
256
-                                 * Loop through the relation attributes.
257
-                                 */
258
-                                foreach ($val as $attr => $val) 
259
-                                {
260
-                                    /**
261
-                                     * Prevent the sub relations or attributes not in the fillable.
262
-                                     */
263
-                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
264
-                                    {
265
-                                        $relationModel->$attr = $val;
266
-                                    }
267
-                                }
268
-                                $relations[$relation][] = $relationModel;
269
-                            }
270
-                            /**
271
-                             * If not collection.
272
-                             */
273
-                            else
274
-                            {
275
-                                /**
276
-                                 * Prevent the sub relations.
277
-                                 */
278
-                                if (gettype($val) !== 'object' && gettype($val) !== 'array') 
279
-                                {
280
-                                    /**
281
-                                     * If the id is present in the data then select the relation model for updating,
282
-                                     * else create new model.
283
-                                     */
284
-                                    $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
255
+								/**
256
+								 * Loop through the relation attributes.
257
+								 */
258
+								foreach ($val as $attr => $val) 
259
+								{
260
+									/**
261
+									 * Prevent the sub relations or attributes not in the fillable.
262
+									 */
263
+									if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
264
+									{
265
+										$relationModel->$attr = $val;
266
+									}
267
+								}
268
+								$relations[$relation][] = $relationModel;
269
+							}
270
+							/**
271
+							 * If not collection.
272
+							 */
273
+							else
274
+							{
275
+								/**
276
+								 * Prevent the sub relations.
277
+								 */
278
+								if (gettype($val) !== 'object' && gettype($val) !== 'array') 
279
+								{
280
+									/**
281
+									 * If the id is present in the data then select the relation model for updating,
282
+									 * else create new model.
283
+									 */
284
+									$relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
285 285
 
286
-                                    /**
287
-                                     * If model doesn't exists.
288
-                                     */
289
-                                    if ( ! $relationModel) 
290
-                                    {
291
-                                        \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
292
-                                    }
286
+									/**
287
+									 * If model doesn't exists.
288
+									 */
289
+									if ( ! $relationModel) 
290
+									{
291
+										\ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
292
+									}
293 293
 
294
-                                    /**
295
-                                     * Prevent attributes not in the fillable.
296
-                                     */
297
-                                    if (array_search($attr, $relationModel->getFillable(), true) !== false) 
298
-                                    {
299
-                                        $relationModel->$attr = $val;
300
-                                        $relations[$relation] = $relationModel;
301
-                                    }
302
-                                }
303
-                            }
304
-                        }
305
-                    }
306
-                }
307
-                /**
308
-                 * If the attribute isn't a relation and prevent attributes not in the fillable.
309
-                 */
310
-                else if (array_search($key, $model->getFillable(), true) !== false)
311
-                {
312
-                    $model->$key = $value;   
313
-                }
314
-            }
315
-            /**
316
-             * Save the model.
317
-             */
318
-            $model->save();
294
+									/**
295
+									 * Prevent attributes not in the fillable.
296
+									 */
297
+									if (array_search($attr, $relationModel->getFillable(), true) !== false) 
298
+									{
299
+										$relationModel->$attr = $val;
300
+										$relations[$relation] = $relationModel;
301
+									}
302
+								}
303
+							}
304
+						}
305
+					}
306
+				}
307
+				/**
308
+				 * If the attribute isn't a relation and prevent attributes not in the fillable.
309
+				 */
310
+				else if (array_search($key, $model->getFillable(), true) !== false)
311
+				{
312
+					$model->$key = $value;   
313
+				}
314
+			}
315
+			/**
316
+			 * Save the model.
317
+			 */
318
+			$model->save();
319 319
             
320
-            /**
321
-             * Loop through the relations array.
322
-             */
323
-            foreach ($relations as $key => $value) 
324
-            {
325
-                /**
326
-                 * If the relation is marked for delete then delete it.
327
-                 */
328
-                if ($value == 'delete' && $model->$key()->count())
329
-                {
330
-                    $model->$key()->delete();
331
-                }
332
-                /**
333
-                 * If the relation is an array.
334
-                 */
335
-                else if (gettype($value) == 'array') 
336
-                {
337
-                    $ids = [];
338
-                    /**
339
-                     * Loop through the relations.
340
-                     */
341
-                    foreach ($value as $val) 
342
-                    {
343
-                        switch (class_basename($model->$key())) 
344
-                        {
345
-                            /**
346
-                             * If the relation is one to many then update it's foreign key with
347
-                             * the model id and save it then add its id to ids array to delete all 
348
-                             * relations who's id isn't in the ids array.
349
-                             */
350
-                            case 'HasMany':
351
-                                $foreignKeyName       = explode('.', $model->$key()->getForeignKey())[1];
352
-                                $val->$foreignKeyName = $model->id;
353
-                                $val->save();
354
-                                $ids[] = $val->id;
355
-                                break;
320
+			/**
321
+			 * Loop through the relations array.
322
+			 */
323
+			foreach ($relations as $key => $value) 
324
+			{
325
+				/**
326
+				 * If the relation is marked for delete then delete it.
327
+				 */
328
+				if ($value == 'delete' && $model->$key()->count())
329
+				{
330
+					$model->$key()->delete();
331
+				}
332
+				/**
333
+				 * If the relation is an array.
334
+				 */
335
+				else if (gettype($value) == 'array') 
336
+				{
337
+					$ids = [];
338
+					/**
339
+					 * Loop through the relations.
340
+					 */
341
+					foreach ($value as $val) 
342
+					{
343
+						switch (class_basename($model->$key())) 
344
+						{
345
+							/**
346
+							 * If the relation is one to many then update it's foreign key with
347
+							 * the model id and save it then add its id to ids array to delete all 
348
+							 * relations who's id isn't in the ids array.
349
+							 */
350
+							case 'HasMany':
351
+								$foreignKeyName       = explode('.', $model->$key()->getForeignKey())[1];
352
+								$val->$foreignKeyName = $model->id;
353
+								$val->save();
354
+								$ids[] = $val->id;
355
+								break;
356 356
 
357
-                            /**
358
-                             * If the relation is many to many then add it's id to the ids array to
359
-                             * attache these ids to the model.
360
-                             */
361
-                            case 'BelongsToMany':
362
-                                $val->save();
363
-                                $ids[] = $val->id;
364
-                                break;
365
-                        }
366
-                    }
367
-                    switch (class_basename($model->$key())) 
368
-                    {
369
-                        /**
370
-                         * If the relation is one to many then delete all 
371
-                         * relations who's id isn't in the ids array.
372
-                         */
373
-                        case 'HasMany':
374
-                            $model->$key()->whereNotIn('id', $ids)->delete();
375
-                            break;
357
+							/**
358
+							 * If the relation is many to many then add it's id to the ids array to
359
+							 * attache these ids to the model.
360
+							 */
361
+							case 'BelongsToMany':
362
+								$val->save();
363
+								$ids[] = $val->id;
364
+								break;
365
+						}
366
+					}
367
+					switch (class_basename($model->$key())) 
368
+					{
369
+						/**
370
+						 * If the relation is one to many then delete all 
371
+						 * relations who's id isn't in the ids array.
372
+						 */
373
+						case 'HasMany':
374
+							$model->$key()->whereNotIn('id', $ids)->delete();
375
+							break;
376 376
 
377
-                        /**
378
-                         * If the relation is many to many then 
379
-                         * detach the previous data and attach 
380
-                         * the ids array to the model.
381
-                         */
382
-                        case 'BelongsToMany':
383
-                            $model->$key()->detach();
384
-                            $model->$key()->attach($ids);
385
-                            break;
386
-                    }
387
-                }
388
-                /**
389
-                 * If the relation isn't array.
390
-                 */
391
-                else
392
-                {
393
-                    switch (class_basename($model->$key())) 
394
-                    {
395
-                        /**
396
-                         * If the relation is one to many or one to one.
397
-                         */
398
-                        case 'BelongsTo':
399
-                            $value->save();
400
-                            $model->$key()->associate($value);
401
-                            $model->save();
402
-                            break;
403
-                    }
404
-                }
405
-            }
377
+						/**
378
+						 * If the relation is many to many then 
379
+						 * detach the previous data and attach 
380
+						 * the ids array to the model.
381
+						 */
382
+						case 'BelongsToMany':
383
+							$model->$key()->detach();
384
+							$model->$key()->attach($ids);
385
+							break;
386
+					}
387
+				}
388
+				/**
389
+				 * If the relation isn't array.
390
+				 */
391
+				else
392
+				{
393
+					switch (class_basename($model->$key())) 
394
+					{
395
+						/**
396
+						 * If the relation is one to many or one to one.
397
+						 */
398
+						case 'BelongsTo':
399
+							$value->save();
400
+							$model->$key()->associate($value);
401
+							$model->save();
402
+							break;
403
+					}
404
+				}
405
+			}
406 406
 
407
-            $saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false;
408
-        });
407
+			$saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false;
408
+		});
409 409
     
410
-        /**
411
-         * return the saved mdel with the given relations.
412
-         */
413
-        return $this->find($model->id, $with);
414
-    }
410
+		/**
411
+		 * return the saved mdel with the given relations.
412
+		 */
413
+		return $this->find($model->id, $with);
414
+	}
415 415
     
416
-    /**
417
-     * Delete record from the storage based on the given
418
-     * condition.
419
-     * 
420
-     * @param  var $value condition value
421
-     * @param  string $attribute condition column name
422
-     * @return void
423
-     */
424
-    public function delete($value, $attribute = 'id', $saveLog = true)
425
-    {
426
-        if ($attribute == 'id') 
427
-        {
428
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
429
-                $model = $this->model->lockForUpdate()->find($value);
430
-                if ( ! $model) 
431
-                {
432
-                    \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value);
433
-                }
416
+	/**
417
+	 * Delete record from the storage based on the given
418
+	 * condition.
419
+	 * 
420
+	 * @param  var $value condition value
421
+	 * @param  string $attribute condition column name
422
+	 * @return void
423
+	 */
424
+	public function delete($value, $attribute = 'id', $saveLog = true)
425
+	{
426
+		if ($attribute == 'id') 
427
+		{
428
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
429
+				$model = $this->model->lockForUpdate()->find($value);
430
+				if ( ! $model) 
431
+				{
432
+					\ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value);
433
+				}
434 434
                 
435
-                $model->delete();
436
-                $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
437
-            });
438
-        }
439
-        else
440
-        {
441
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
442
-                call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
443
-                    $model->delete();
444
-                    $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
445
-                });
446
-            });   
447
-        }
448
-    }
435
+				$model->delete();
436
+				$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
437
+			});
438
+		}
439
+		else
440
+		{
441
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
442
+				call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
443
+					$model->delete();
444
+					$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
445
+				});
446
+			});   
447
+		}
448
+	}
449 449
     
450
-    /**
451
-     * Fetch records from the storage based on the given
452
-     * id.
453
-     * 
454
-     * @param  integer $id
455
-     * @param  array   $relations
456
-     * @param  array   $columns
457
-     * @return object
458
-     */
459
-    public function find($id, $relations = [], $columns = array('*'))
460
-    {
461
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
462
-    }
450
+	/**
451
+	 * Fetch records from the storage based on the given
452
+	 * id.
453
+	 * 
454
+	 * @param  integer $id
455
+	 * @param  array   $relations
456
+	 * @param  array   $columns
457
+	 * @return object
458
+	 */
459
+	public function find($id, $relations = [], $columns = array('*'))
460
+	{
461
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
462
+	}
463 463
     
464
-    /**
465
-     * Fetch records from the storage based on the given
466
-     * condition.
467
-     * 
468
-     * @param  array   $conditions array of conditions
469
-     * @param  array   $relations
470
-     * @param  string  $sortBy
471
-     * @param  boolean $desc
472
-     * @param  array   $columns
473
-     * @return collection
474
-     */
475
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
476
-    {
477
-        $conditions = $this->constructConditions($conditions);
478
-        $sort       = $desc ? 'desc' : 'asc';
479
-        return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
480
-    }
464
+	/**
465
+	 * Fetch records from the storage based on the given
466
+	 * condition.
467
+	 * 
468
+	 * @param  array   $conditions array of conditions
469
+	 * @param  array   $relations
470
+	 * @param  string  $sortBy
471
+	 * @param  boolean $desc
472
+	 * @param  array   $columns
473
+	 * @return collection
474
+	 */
475
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
476
+	{
477
+		$conditions = $this->constructConditions($conditions);
478
+		$sort       = $desc ? 'desc' : 'asc';
479
+		return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
480
+	}
481 481
 
482
-    /**
483
-     * Fetch the first record from the storage based on the given
484
-     * condition.
485
-     *
486
-     * @param  array   $conditions array of conditions
487
-     * @param  array   $relations
488
-     * @param  array   $columns
489
-     * @return object
490
-     */
491
-    public function first($conditions, $relations = [], $columns = array('*'))
492
-    {
493
-        $conditions = $this->constructConditions($conditions);
494
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
495
-    }
482
+	/**
483
+	 * Fetch the first record from the storage based on the given
484
+	 * condition.
485
+	 *
486
+	 * @param  array   $conditions array of conditions
487
+	 * @param  array   $relations
488
+	 * @param  array   $columns
489
+	 * @return object
490
+	 */
491
+	public function first($conditions, $relations = [], $columns = array('*'))
492
+	{
493
+		$conditions = $this->constructConditions($conditions);
494
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
495
+	}
496 496
 
497
-    /**
498
-     * Build the conditions recursively for the retrieving methods.
499
-     * @param  array $conditions
500
-     * @return array
501
-     */
502
-    protected function constructConditions($conditions)
503
-    {   
504
-        $conditionString = '';
505
-        $conditionValues = [];
506
-        foreach ($conditions as $key => $value) 
507
-        {
508
-            if ($key == 'and') 
509
-            {
510
-                $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
511
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
512
-            }
513
-            else if ($key == 'or')
514
-            {
515
-                $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
516
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
517
-            }
518
-            else
519
-            {
520
-                $conditionString  .= $key . '=? {op} ';
521
-                $conditionValues[] = $value;
522
-            }
523
-        }
524
-        $conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
525
-        return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
526
-    }
497
+	/**
498
+	 * Build the conditions recursively for the retrieving methods.
499
+	 * @param  array $conditions
500
+	 * @return array
501
+	 */
502
+	protected function constructConditions($conditions)
503
+	{   
504
+		$conditionString = '';
505
+		$conditionValues = [];
506
+		foreach ($conditions as $key => $value) 
507
+		{
508
+			if ($key == 'and') 
509
+			{
510
+				$conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
511
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
512
+			}
513
+			else if ($key == 'or')
514
+			{
515
+				$conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
516
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
517
+			}
518
+			else
519
+			{
520
+				$conditionString  .= $key . '=? {op} ';
521
+				$conditionValues[] = $value;
522
+			}
523
+		}
524
+		$conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
525
+		return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
526
+	}
527 527
 
528
-    /**
529
-     * Abstract method that return the necessary 
530
-     * information (full model namespace)
531
-     * needed to preform the previous actions.
532
-     * 
533
-     * @return string
534
-     */
535
-    abstract protected function getModel();
528
+	/**
529
+	 * Abstract method that return the necessary 
530
+	 * information (full model namespace)
531
+	 * needed to preform the previous actions.
532
+	 * 
533
+	 * @return string
534
+	 */
535
+	abstract protected function getModel();
536 536
 }
537 537
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/ModelObservers/SettingsObserver.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -5,59 +5,59 @@
 block discarded – undo
5 5
  */
6 6
 class SettingsObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
12
-
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
17
-
18
-    /**
19
-     * Prevent the creating of the settings.
20
-     * 
21
-     * @param  object $model the model beign created.
22
-     * @return void
23
-     */
24
-    public function creating($model)
25
-    {
26
-        \ErrorHandler::cannotCreateSetting();
27
-    }
28
-
29
-    public function created($model)
30
-    {
31
-        //
32
-    }
33
-
34
-    /**
35
-     * Prevent updating of the setting key.
36
-     * 
37
-     * @param  object $model the model beign updated.
38
-     * @return void
39
-     */
40
-    public function updating($model)
41
-    {
42
-        if ($model->getOriginal()['key'] !== $model->key) 
43
-        {
44
-            \ErrorHandler::cannotUpdateSettingKey();
45
-        }
46
-    }
47
-
48
-    public function updated($model)
49
-    {
50
-        //
51
-    }
52
-
53
-    public function deleting($model)
54
-    {
55
-        //
56
-    }
57
-
58
-    public function deleted($model)
59
-    {
60
-        //
61
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12
+
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17
+
18
+	/**
19
+	 * Prevent the creating of the settings.
20
+	 * 
21
+	 * @param  object $model the model beign created.
22
+	 * @return void
23
+	 */
24
+	public function creating($model)
25
+	{
26
+		\ErrorHandler::cannotCreateSetting();
27
+	}
28
+
29
+	public function created($model)
30
+	{
31
+		//
32
+	}
33
+
34
+	/**
35
+	 * Prevent updating of the setting key.
36
+	 * 
37
+	 * @param  object $model the model beign updated.
38
+	 * @return void
39
+	 */
40
+	public function updating($model)
41
+	{
42
+		if ($model->getOriginal()['key'] !== $model->key) 
43
+		{
44
+			\ErrorHandler::cannotUpdateSettingKey();
45
+		}
46
+	}
47
+
48
+	public function updated($model)
49
+	{
50
+		//
51
+	}
52
+
53
+	public function deleting($model)
54
+	{
55
+		//
56
+	}
57
+
58
+	public function deleted($model)
59
+	{
60
+		//
61
+	}
62 62
 
63 63
 }
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/Interfaces/RepositoryInterface.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -3,108 +3,108 @@
 block discarded – undo
3 3
 interface RepositoryInterface
4 4
 {
5 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
-     */
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 14
 	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
15 15
  	
16
-    /**
17
-     * Fetch all records with relations from storage in pages 
18
-     * that matche the given query.
19
-     * 
20
-     * @param  string  $query
21
-     * @param  integer $perPage
22
-     * @param  array   $relations
23
-     * @param  array   $sortBy
24
-     * @param  array   $desc
25
-     * @param  array   $columns
26
-     * @return collection
27
-     */
28
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
16
+	/**
17
+	 * Fetch all records with relations from storage in pages 
18
+	 * that matche the given query.
19
+	 * 
20
+	 * @param  string  $query
21
+	 * @param  integer $perPage
22
+	 * @param  array   $relations
23
+	 * @param  array   $sortBy
24
+	 * @param  array   $desc
25
+	 * @param  array   $columns
26
+	 * @return collection
27
+	 */
28
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
29 29
 
30 30
 	/**
31
-     * Fetch all records with relations from storage in pages.
32
-     * 
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 paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
31
+	 * Fetch all records with relations from storage in pages.
32
+	 * 
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 paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
41 41
  	
42 42
 	/**
43
-     * Fetch all records with relations based on
44
-     * the given condition from storage in pages.
45
-     * 
46
-     * @param  array   $conditions array of conditions
47
-     * @param  integer $perPage
48
-     * @param  array   $relations
49
-     * @param  array   $sortBy
50
-     * @param  array   $desc
51
-     * @param  array   $columns
52
-     * @return collection
53
-     */
54
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
43
+	 * Fetch all records with relations based on
44
+	 * the given condition from storage in pages.
45
+	 * 
46
+	 * @param  array   $conditions array of conditions
47
+	 * @param  integer $perPage
48
+	 * @param  array   $relations
49
+	 * @param  array   $sortBy
50
+	 * @param  array   $desc
51
+	 * @param  array   $columns
52
+	 * @return collection
53
+	 */
54
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
55 55
 
56
-     /**
57
-     * Save the given model/models to the storage.
58
-     * 
59
-     * @param  array   $data
60
-     * @param  boolean $saveLog
61
-     * @return object
62
-     */
63
-    public function save(array $data, $saveLog = true);
56
+	 /**
57
+	  * Save the given model/models to the storage.
58
+	  * 
59
+	  * @param  array   $data
60
+	  * @param  boolean $saveLog
61
+	  * @return object
62
+	  */
63
+	public function save(array $data, $saveLog = true);
64 64
 
65 65
 	/**
66
-     * Delete record from the storage based on the given
67
-     * condition.
68
-     * 
69
-     * @param  var     $value condition value
70
-     * @param  string  $attribute condition column name
71
-     * @return integer affected rows
72
-     */
73
-    public function delete($value, $attribute = 'id');
66
+	 * Delete record from the storage based on the given
67
+	 * condition.
68
+	 * 
69
+	 * @param  var     $value condition value
70
+	 * @param  string  $attribute condition column name
71
+	 * @return integer affected rows
72
+	 */
73
+	public function delete($value, $attribute = 'id');
74 74
  	
75 75
 	/**
76
-     * Fetch records from the storage based on the given
77
-     * id.
78
-     * 
79
-     * @param  integer $id
80
-     * @param  array   $relations
81
-     * @param  array   $columns
82
-     * @return object
83
-     */
84
-    public function find($id, $relations = [], $columns = array('*'));
76
+	 * Fetch records from the storage based on the given
77
+	 * id.
78
+	 * 
79
+	 * @param  integer $id
80
+	 * @param  array   $relations
81
+	 * @param  array   $columns
82
+	 * @return object
83
+	 */
84
+	public function find($id, $relations = [], $columns = array('*'));
85 85
  	
86 86
 	/**
87
-     * Fetch records from the storage based on the given
88
-     * condition.
89
-     * 
90
-     * @param  array   $conditions array of conditions
91
-     * @param  array   $relations
92
-     * @param  array   $sortBy
93
-     * @param  array   $desc
94
-     * @param  array   $columns
95
-     * @return collection
96
-     */
97
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
87
+	 * Fetch records from the storage based on the given
88
+	 * condition.
89
+	 * 
90
+	 * @param  array   $conditions array of conditions
91
+	 * @param  array   $relations
92
+	 * @param  array   $sortBy
93
+	 * @param  array   $desc
94
+	 * @param  array   $columns
95
+	 * @return collection
96
+	 */
97
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
98 98
 
99
-    /**
100
-     * Fetch the first record fro the storage based on the given
101
-     * condition.
102
-     * 
103
-     * @param  array   $conditions array of conditions
104
-     * @param  var     $value condition value
105
-     * @param  array   $relations
106
-     * @param  array   $columns
107
-     * @return object
108
-     */
109
-    public function first($conditions, $relations = [], $columns = array('*'));
99
+	/**
100
+	 * Fetch the first record fro the storage based on the given
101
+	 * condition.
102
+	 * 
103
+	 * @param  array   $conditions array of conditions
104
+	 * @param  var     $value condition value
105
+	 * @param  array   $relations
106
+	 * @param  array   $columns
107
+	 * @return object
108
+	 */
109
+	public function first($conditions, $relations = [], $columns = array('*'));
110 110
 }
111 111
\ No newline at end of file
Please login to merge, or discard this patch.