php - How to differentiate profiles? -


i have 2 types of user: client, manager. stored in separated tables.

each of have unique nickname.

so, need open profile nickname.

for client is:

$client = client::where("nickname", $nickname) 

for manager is:

$manager = manager::where("nickname", $nickname) 

so, try make universal function dewtect client , manager , execute appropriate query.

how can improve code , detect type of user nickename?

you should use 1 model this, guess best way handle clients , managers.

if reason want use 2 models, can create method , put in client model since of queries clients:

public function getclientormanagerbynickname($nickname) {     $client = $this->where('nickname', $nickname)->first();      return is_null($client) ? (new manager)->where('nickname', $nickname)->first() : $client; } 

this code create 1 query if client found , return client. or create 2 queires , return manager. if there no client , manager nickname, return null.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -