@@ -42,18 +42,113 @@ public function getRememberToken(){
4242 }
4343
4444 public function setRememberToken ($ value ){
45- $ this ->remember_token = $ value ;
46- }
45+ $ this ->remember_token = $ value ;
46+ }
47+
48+ public function getReminderEmail (){
49+ $ email = Input::only ('email ' );
50+ return $ email ['email ' ];
51+ }
4752
48- public function getReminderEmail (){
49- $ email = Input::only ('email ' );
50- return $ email ['email ' ];
51- }
5253
54+ public function getRememberTokenName (){
55+ return $ this ->remember_token_name ;
56+ }
57+
58+
59+ /**
60+ * To get all Admins that has $key and $value on extradata field
61+ * @param $key
62+ * @param $value
63+ * @return mixed
64+ */
65+ public function getAllExtraData ($ key , $ value ){
66+ //defined by local scope
67+ return Admin::getExtraData ($ key , $ value )->get ();
68+ //return Admin::where('extradata->' + $key, $value)->get();
69+ //JSON_CONTAINS() function accepts the JSON field being searched and another to compare against.
70+ // It returns 1 when a match is found, e.g.
71+ //return Admin::whereRaw('JSON_CONTAINS(extradata->"$.' + $key + '", \'["' + $value + '"]\')')->get();
72+ }
5373
54- public function getRememberTokenName (){
55- return $ this ->remember_token_name ;
56- }
74+ /**
75+ * Get all the Admins who has $query in $key on extradata field
76+ * @param $key
77+ * @param $query
78+ * @return mixed
79+ */
80+ public function getSearchInExtraData ($ key , $ query ){
81+ //defined by local scope
82+ return Admin::searchInExtraData ($ key , $ query )->get ();
83+ //return Admin::where('extradata->' + $key, 'like', '%'+ $query + '%')->get();
84+ //JSON_SEARCH() function returns the path to the given match or NULL when there’s no match.
85+ // It is passed the JSON document being searched, 'one' to find the first match or 'all' to find all matches, and a search string, e.g.
86+ //return Admin::whereRaw('JSON_SEARCH(extradata->"$.' + $key + '", "one", "%'+ $query + '%") IS NOT NULL')->get();
87+ }
88+
89+ /**
90+ * add or update admin's picture.
91+ * @param $pic_base64_encoded
92+ */
93+ public function updateAdminPicture ($ pic_base64_encoded ){
94+ //use forceFill() which will bypass the mass assignment check to perform update on any JSON path,
95+ // if path is not there, it will be created and if it’s present it will be updated accordingly.
96+ $ this ->forceFill (['extradata->picture ' => $ pic_base64_encoded ]);
97+
98+ # Save the changes
99+ $ this ->update ();
100+ }
101+
102+ /**
103+ * find admin by primary key id
104+ * @param $admin_id
105+ * @return mixed
106+ */
107+ public function findById ($ admin_id ){
108+ // Retrieve a model by its primary key...
109+ $ admin = Admin::find ($ admin_id );
110+ // Retrieve the first model matching the query constraints...
111+ //$admin = Admin::where('id', $admin_id)->first();
112+ return $ admin ;
113+ }
114+
115+ /**
116+ * Scope a query to get admin by id.
117+ * @param $query
118+ * @param $admin_id
119+ * @return mixed
120+ */
121+ public function scopeFindById ($ query , $ admin_id ){
122+ return $ query ->where ('id ' , $ admin_id );
123+ }
124+
125+ /**
126+ * Scope a query to get admin by a $key and $value in extradata.
127+ * @param $query
128+ * @param $key
129+ * @param $value
130+ * @return mixed
131+ */
132+ public function scopeGetExtraData ($ query , $ key , $ value ){
133+ //JSON_CONTAINS() function accepts the JSON field being searched and another to compare against.
134+ // It returns 1 when a match is found, e.g.
135+ return $ query ->whereRaw ('JSON_CONTAINS(extradata->"$. ' + $ key + '", \'[" ' + $ value + '"] \') ' );
136+ //return $query->where('extradata->' + $key, $value);
137+ }
138+
139+ /**
140+ * Scope a query to get admin by a $key and search in $value.
141+ * @param $query
142+ * @param $key
143+ * @param $query_value
144+ * @return mixed
145+ */
146+ public function scopeSearchInExtraData ($ query , $ key , $ query_value ){
147+ //JSON_SEARCH() function returns the path to the given match or NULL when there’s no match.
148+ // It is passed the JSON document being searched, 'one' to find the first match or 'all' to find all matches, and a search string, e.g.
149+ return $ query ->whereRaw ('JSON_SEARCH(extradata->"$. ' + $ key + '", "one", "% ' + $ query_value + '%") IS NOT NULL ' );
150+ //return $query->where('extradata->' + $key, 'like', '%'+ $query_value + '%');
151+ }
57152
58153
59154 protected $ fillable = array ('first_name ' , 'last_name ' , 'email ' , 'password ' );
0 commit comments