Support the ongoing development of Laravel.io →
Session Database Eloquent

i'm trying to displaying single data like this

  id  TenantID  name username  password        sendername senderpassword     
------  --------     -------- --------------  --------------------- ----------------- -------------------------
     4  1         yovhi2     yovhi2   somepassword          a             a

here my table

tb.users
    id  TenantID  name      username  password            
------  --------  --------  --------  -------------
     1  1         yovhi     yovhi  
     4  1         yovhi2     yovhi2
 
tb.masking
 id  TenantID  senderid   sendername    senderpassword  
------  --------  ---------  ------------  ----------------
     1         1  a          a             a
     2         2  b          b             b  

when joining table, i just get id user is only 1 when i'm login as user id 4, and when i'm give where clause id=session id in my code, this result is null.

here my Masking model

public function User()
	{
		return $this->belongsTo('User','TenantID');
	}

controller

public function home()
        {
                $user=Masking::with('User')->where('TenantID','=',Session::get('tenant'))->
                where('id','=',Session::get('user_id'))->get();
  
                foreach ($user as $key) {
                 var_dump($key->User->id);
                }
                //return View::make('profile')->with(compact('key'))->with(compact('user'));
        }
Last updated 2 years ago.
0
->where('id','=',Session::get('user_id'))->get();

You are getting a masking object by user's ID, in SQL language it's like:

SELECT * FROM `masking` WHERE `id` = <user_id>
Last updated 10 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

scarings scarings Joined 26 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.